c# - Entity Framework: Unable to create a constant value of type **. Only primitive types or enumeration types are supported in this context -
i have query:
public override ienumerable<order> executequery(movierentalcontext database) { return order in database.orders (customer == null || customer.id == order.customerid) select order; }
where customer field in class. there order class
public class order: entity { [required] public copy copy { get; set; } public customer customer { get; set; } public datetime orderdate { get; set; } public datetime estimatedreturndate { get; set; } public salesman salesman { get; set; } public datetime? actualreturndate { get; set; } public decimal price { get; set; } [foreignkey("customer")] public long customerid { get; set; } }
entity contains id. want orders of customer, during execution query exception thrown:
unable create constant value of type >'movierental.dataaccess.models.customer'. primitive types or enumeration >types supported in context.
i tried found stil doesn't work. problem?
i'd customer == null
code causing this. ef trying convert sql customer not in context. try , take condition outside of query.
ie
public override ienumerable<order> executequery(movierentalcontext database) { if (customer != null) { return order in database.orders order.customerid == customer.id select order; } else { return order in database.orders select order; } }
Comments
Post a Comment