c# - The specified type member 'Product' is not supported in LINQ to Entities -


i'm getting error 'product' not supported in linq entities whilst using cartitems.product.unitcost when trying total of basket.

public decimal gettotal()     {         //multiply price count of item price each item in cart , them sum prices         decimal? total = (from cartitems in db.shoppingbaskets cartitems.basketid == shoppingcartid select (int?)cartitems.basketquantity * cartitems.product.unitcost).sum();          return total ?? decimal.zero;     } 

i tried splitting query see if fix problem

int? quantity = (from cartitems in db.shoppingbaskets cartitems.basketid == shoppingcartid select (int?)cartitems.basketquantity).sum();  decimal? price = (from cartitems in db.shoppingbaskets cartitems.basketid == shoppingcartid select cartitems.product.unitcost).sum(); 

i same problem second separate query 'product'.

product class

public partial class product {     public product()     {         this.ordercheckouts = new hashset<ordercheckout>();         this.productreviews = new hashset<productreview>();     }      public int productid { get; set; }     public int categoryid { get; set; }     public int manufacturerid { get; set; }     public string productname { get; set; }     public string productcode { get; set; }     public decimal unitcost { get; set; }     public int unitquantity { get; set; }     public string productdescription { get; set; }     public string productimage { get; set; }      public virtual category category { get; set; }     public virtual manufacturer manufacturer { get; set; }     public virtual icollection<ordercheckout> ordercheckouts { get; set; }     public virtual icollection<productreview> productreviews { get; set; } } 

shoppingbasket class

public partial class shoppingbasket {     public int cartid { get; set; }     public string basketid { get; set; }     public int basketquantity { get; set; }     public int productid { get; set; }     public virtual product product { get; set; } } 

could explain problem more , how can solve this? thanks!

i think it's because entity framework hasn't created relationship between shoppingbasket , product. try adding:

public virtual icollection<shoppingbasket> shoppingbaskets { get; set; } 

to product class.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -