实体框架中LINQ to Entities不支持LINQ表达式节点类型“Invoke” [英] The LINQ expression node type 'Invoke' is not supported in LINQ to Entities in entity framework

查看:985
本文介绍了实体框架中LINQ to Entities不支持LINQ表达式节点类型“Invoke”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮我解决问题。我正在使用以下代码:

  public IEnumerable< InvoiceHeader> GetData(Expression< Func< InvoiceHeader,bool>>谓词)
{
返回AccountsContext.InvoiceHeaders.Include(Company)。Include(Currency)
.Include(BusinessPartnerRoleList ).Include(DocumentType)
.Where(谓词);
}

.....



在我的代码中,我使用如下

 表达式< Func< InvoiceHeader,bool>> predicate = PredicateBuilder.True< InvoiceHeader>(); 
predicate = predicate.And(o => o.CompanyId == oInvoiceHeader.CompanyId);
列表< InvoiceHeader> lstInvheader = GETDATA(谓词).ToList();

通过这样做,我得到了异常。 [System.NotSupportedException] ---
{LINQ to Entities不支持LINQ表达式节点类型Invoke。}

解决方案

可以使用Joe Albahari的LINQKIT中存在的AsExpandable()方法来解决此问题。他是与我看到你正在使用的 PredicateBuilder 的创建者。


如果查询实体框架,将最后一行更改为:



return objectContext.Products.AsExpandable()。Where(predicate);


您可以抓取LINQKIT DLL 这里或通过NuGet软件包 here 进行安装。



它一定会解决你的问题,因为它已经解决了我的。


can anyone help me out in solving my issue. I am using the code given below:

public IEnumerable<InvoiceHeader> Getdata(Expression<Func<InvoiceHeader, bool>> predicate)
{
    return AccountsContext.InvoiceHeaders.Include("Company").Include("Currency")
        .Include("BusinessPartnerRoleList").Include("DocumentType")
        .Where(predicate);
}

.....

In my code I am using as below

Expression<Func<InvoiceHeader, bool>> predicate = PredicateBuilder.True<InvoiceHeader>();
predicate = predicate.And(o => o.CompanyId == oInvoiceHeader.CompanyId);
List<InvoiceHeader> lstInvheader=Getdata(predicate).ToList();

By doing this I am getting the exception . [System.NotSupportedException] --- {"The LINQ expression node type 'Invoke' is not supported in LINQ to Entities."}

解决方案

This problem can be solved using the AsExpandable() method present in LINQKIT by Joe Albahari. He's the same creator of PredicateBuilder that I see you're using.

If querying with Entity Framework, change the last line to this:

return objectContext.Products.AsExpandable().Where(predicate);

You can grab LINQKIT DLL here or install it through a NuGet package here.

It'll certainly solve your problem because it has solved mine.

这篇关于实体框架中LINQ to Entities不支持LINQ表达式节点类型“Invoke”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆