开发者

How to create a Linq To Entities expression

开发者 https://www.devze.com 2022-12-25 03:04 出处:网络
HI, I\'m using Linq To Entities and I\'d like to convert this return db.Products .Where(p => p.idUser.Equals(id) &&

HI, 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))

into something like

Func<Genre, bool> expr = g => g.visible

return db.Products
         .Where(p => p.idUser.Equals(id) && 
                     p.Category.Genre.Any(expr))

s开发者_如何转开发o I can add more complexity with something like this

Func<Genre, bool> expr = g => g.visible
expr += g => g.position < 5

But I always have an 'internal 1025 error .NET'. Can anyone help me, please? Thanks.


You need to use Expressions, 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号