Linqkit错误:“LINQ to Entities”中不支持LINQ表达式节点类型“Invoke”。 [英] Linqkit error:"The LINQ expression node type 'Invoke' is not supported in LINQ to Entities"

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

问题描述

我正在使用Linqkit创建一个Where或者构造。但是当我尝试运行它时,它给出了以下错误:"LINQ to Entities中不支持LINQ表达式节点类型'Invoke'"

Hi,

Im using the Linqkit to create a where Or construction. But when I try to run it it gives me the following error: "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities"

我的代码:

IQueryable<CatalogArticle> query = ((CMSCatalogEntities)ctx).CatalogArticleSet;
Expression<Func<CatalogArticle, bool>> predicate = PredicateBuilder.False<CatalogArticle>();

if (!string.IsNullOrEmpty(itemCode))
{
predicate = predicate.Or(u => u.ItemCode.Contains(itemCode));
}

if (!string.IsNullOrEmpty(name))
{
predicate = predicate.Or(u => u.Name.Contains(name));
}

//Paging - page 1 is first page (not 0 based)
//Only when pageSize is bigger than 0, so paging can be disabled
if (pageSize > 0)
{
query = query.OrderBy(x => x.Name).Skip((pageIndex - 1) * pageSize).Take(pageSize);
}

query = query.Where(predicate);

有人能告诉我我做错了吗?

Can someone tell me what I am doing wrong?

Thx

推荐答案

在工作之前,在实体集上使用AsExpandable扩展方法。您需要将代码的第一行修改为:

Use the AsExpandable extension method on the entity set before working. You need to modify the first line of your code to be:

IQueryable<CatalogArticle> query = ((CMSCatalogEntities)ctx).CatalogArticleSet.AsExpandable();

这在作者的网站上有记载:

This is documented in the author's website:

http: //www.albahari.com/nutshell/linqkit.aspx

http://www.albahari.com/nutshell/linqkit.aspx


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

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