开发者

c# LINQ to Entities: unsupported type

in a solution I've got a interface class IUser and, in another project, a class implementing User implementing IUser.

Executing Linq queries on IUser objects throws me the following exception:

The specified type member 'Username' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

Can you please help me to solve this? Best Regards

Sample query(Users() returns IQueryable<IUser>:
var c= (from user in bank.Users()
                           where user.Username == "anUser"
                           select user);

here below some code:

//the interface

public interface IUser
{

    stri开发者_开发问答ng Username { get; }
}

// the implementation
public partial class User : IUser
{

   public string Bankname
    {
        get
        {
            return bank_name;
        }
    }

// the partial class generated from the entity model
[EdmEntityTypeAttribute(NamespaceName="Database1Model", Name="User")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class User : EntityObject
{
    #region Factory Method

    /// <summary>
    /// Create a new User object.
    /// </summary>
    /// <param name="user_name">Initial value of the user_name property.</param>
    /// <param name="pass_hash">Initial value of the pass_hash property.</param>
    /// <param name="is_admin">Initial value of the is_admin property.</param>
    /// <param name="bank_name">Initial value of the bank_name property.</param>
    /// <param name="is_enabled">Initial value of the is_enabled property.</param>
    public static User CreateUser(global::System.String user_name, global::System.String pass_hash, global::System.Boolean is_admin, global::System.String bank_name, global::System.Boolean is_enabled)
    {
        User user = new User();
        user.user_name = user_name;
        user.pass_hash = pass_hash;
        user.is_admin = is_admin;
        user.bank_name = bank_name;
        user.is_enabled = is_enabled;
        return user;
    }

    #endregion
    #region Primitive Properties

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String user_name
    {
        get
        {
            return _user_name;
        }
        set
        {
            if (_user_name != value)
            {
                Onuser_nameChanging(value);
                ReportPropertyChanging("user_name");
                _user_name = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("user_name");
                Onuser_nameChanged();
            }
        }
    }
    private global::System.String _user_name;
    partial void Onuser_nameChanging(global::System.String value);
    partial void Onuser_nameChanged();
.
.
.
.
}    


Your UserName property doesn't have a Set accessor.

If your property doesn't implement a set accessor, the Entity Framework can't set the value of the property in that entity :)

You will need to define a setter for UserName, this could be done in your concrete class.


i got through this using .ToArray().AsQueryable(); on my IQueryable result..., in the example right into the method bank.Users().

Thanks for your help anyway

Best Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜