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

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

问题描述

谁能帮我解决我的问题。我使用如下代码:

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);
}



......

.....

在我的代码我使用如下

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表达式节点类型调用不LINQ支持实体。}

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

推荐答案

这个问题可以利用存在于由乔阿尔巴哈利LINQKIT的AsExpandable()方法来解决。他是 PredicateBuilder ,我看到你正在使用的相同的创造者。

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:

返回objectContext.Products.AsExpandable(),其中(谓语);

您可以抓住LINQKIT DLL的这里或通过这里一包的NuGet 安装它。

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表达式节点类型“调用”不支持LINQ到实体框架的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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