31991

Question:
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))
so 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.
Answer1:You need to use Expression
s, not delegates. You can use the <a href="http://www.albahari.com/nutshell/predicatebuilder.aspx" rel="nofollow">PredicateBuilder
</a> class by Joseph Albahari to build your predicate dynamically :
Expression<Func<Genre, bool>> expr = g => g.visible;
expr = expr.And(g => g.position < 5);