LINQ to Entities 无法识别该方法
public IQueryable<Product> GetModelsInBrand(int BrandId)
{
IQueryable<Product> query =
from Product
in ObjectContext.Products.Where(p => (p.BrandId == BrandId))
orderby Product.Model
select Product;
query = query.Distinct(new ProductByModelEqualityComparer());
return query;
}
执行返回查询后,我得到
查询“GetModelsInBrand”的加载操作失败。 LINQ to Entities 无法识别该方法。”
任何人都可以帮助纠正它吗?
public IQueryable<Product> GetModelsInBrand(int BrandId)
{
IQueryable<Product> query =
from Product
in ObjectContext.Products.Where(p => (p.BrandId == BrandId))
orderby Product.Model
select Product;
query = query.Distinct(new ProductByModelEqualityComparer());
return query;
}
After return query was executed, I got
Load operation failed for query 'GetModelsInBrand'. LINQ to Entities does not recognize the method."
Can anyone help to correct it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LINQ-to-entities 可能不支持您在
ProductByModelEqualityComparer
中编写的代码。您可以在调用Distinct
之前调用AsEnumerable
,这将使Distinct
通过 linq-to-objects 执行,但不会是IQueryable
不再:Probably LINQ-to-entities doesn't support the code which you've written in
ProductByModelEqualityComparer
. You can callAsEnumerable
before callingDistinct
, this will makeDistinct
executed via linq-to-objects but it won't beIQueryable
anymore: