如何创建Linq To Entities表达式 [英] How to create a Linq To Entities expression
本文介绍了如何创建Linq To Entities表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Linq To Entities,我想将其转换
I'm using Linq To Entities and I'd like to convert this
return db.Products
.Where(p => p.idUser.Equals(id) &&
p.Category.Genre.Any(g => g.visible))
变成类似
Func<Genre, bool> expr = g => g.visible
return db.Products
.Where(p => p.idUser.Equals(id) &&
p.Category.Genre.Any(expr))
所以我可以用这样的东西增加更多的复杂性
so I can add more complexity with something like this
Func<Genre, bool> expr = g => g.visible
expr += g => g.position < 5
但是我总是有一个内部1025错误.NET". 有人可以帮我吗? 谢谢.
But I always have an 'internal 1025 error .NET'. Can anyone help me, please? Thanks.
推荐答案
您需要使用Expression
,而不是委托.您可以使用Joseph Albahari的 PredicateBuilder
类来动态构建谓词: /p>
You need to use Expression
s, not delegates. You can use the PredicateBuilder
class by Joseph Albahari to build your predicate dynamically :
Expression<Func<Genre, bool>> expr = g => g.visible;
expr = expr.And(g => g.position < 5);
这篇关于如何创建Linq To Entities表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文