c# - Entity Framework 中的 LINQ to Entities 不支持 LINQ 表达式节点类型 'Invoke'

标签 c# linq entity-framework expression predicate

谁能帮我解决我的问题。我正在使用下面给出的代码:

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/

相关文章:

c# - 如何找出该语句生成的实际 SQL?

c# - Webapi odata扩展 Entity Framework 功能

c# - 异步 - 等待直到有人尝试连接

c# - .net 移动文件失去原始和父文件夹安全权限

c# - 使用 C#、Ajax、Jquery 的 Web 服务不适用于 ASP.Net

c# - 使用 C# 将记录插入 MySQL 数据库

c# - 为什么带有Func参数的.Where()执行查询?

c# - LINQ to Entities 仅支持转换 EDM 基元或枚举类型错误

c# - 将 LINQ 匿名类型转换为 IList<> 时出错

c# - 如何选择按月分组的行