谁能帮我解决我的问题。我正在使用下面给出的代码:
public IEnumerable<InvoiceHeader> Getdata(Expression<Func<InvoiceHeader, bool>> predicate)
{
return AccountsContext.InvoiceHeaders.Include("Company").Include("Currency")
.Include("BusinessPartnerRoleList").Include("DocumentType")
.Where(predicate);
}
.....
在我的代码中,我使用如下
Expression<Func<InvoiceHeader, bool>> predicate = PredicateBuilder.True<InvoiceHeader>();
predicate = predicate.And(o => o.CompanyId == oInvoiceHeader.CompanyId);
List<InvoiceHeader> lstInvheader=Getdata(predicate).ToList();
通过这样做我得到了异常。 [System.NotSupportedException] --- {“LINQ to Entities 不支持 LINQ 表达式节点类型‘Invoke’。”}
最佳答案
可以使用 Joe Albahari 在 LINQKIT 中提供的 AsExpandable() 方法解决此问题。他是我看到您正在使用的 PredicateBuilder
的创建者。
If querying with Entity Framework, change the last line to this:
return objectContext.Products.AsExpandable().Where(predicate);
您可以获取 LINQKIT DLL here或者通过 NuGet 包安装它 here .
它肯定会解决你的问题,因为它已经解决了我的问题。
关于c# - Entity Framework 中的 LINQ to Entities 不支持 LINQ 表达式节点类型 'Invoke',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741667/