Problem :
I have one entity type called product which is generated by the entity framework. I have tried to write below query
public IMyQueryable<Product> GetProducts(int myCategoryID)
{
return from prod in db.Products
where prod.CategoryID== myCategoryID
select new Product { Name = prod.Name};
}
My below written code throws a following error :
var myproducts = myproductRepository.GetProducts(1).Tolist();
“The entity or complex type Shop.Product cannot be constructed in a LINQ to Entities query”
However when I try to use select p
instead of the long one select new Product { Name = p.Name};
it miraculously works correctly.
How can I perform the custom select section?