最佳答案
Product
的实体类型是由实体框架生成的。
我写了这个查询
public IQueryable<Product> GetProducts(int categoryID)
{
return from p in db.Products
where p.CategoryID== categoryID
select new Product { Name = p.Name};
}
下面的代码抛出以下错误:
"实体或复杂类型Shop。产品不能构造在
. LINQ to Entities query"
var products = productRepository.GetProducts(1).Tolist();
但是当我使用select p
而不是select new Product { Name = p.Name};
时,它可以正常工作。
如何执行自定义选择节?