I've been trying to create a dynamic linq query given an arbitrary
number of where clauses like this:
//Predicate returning ingredients with name containing the
keyword
Func<string, Func<Ingredient, bool>> buildKeywordPredicate
=
(keyword) => ingredient => ingredient.Name.Contains
(keyword);
//Chain 2 predicates together
Func<Func<Ingredient,bool>, Func<Ingredient, bool>,
Func<Ingredient, bool>> chainPredicates =
(pred1, pred2) =>
x => pred1(x) || pred2(x);
//Generate the complete filter from a list of keywords
Func<Ingredient,bool> filter = null;
foreach (var keyword in keywords) {
filter = filter == null
? buildKeywordPredicate(keyword)
: chainPredicates(filter, buildKeywordPredicate
(keyword));
}
return Session.Linq<Ingredient>().Where(filter);
However nothing is returned and I can see that no where clauses are
used in the generated SQL.
I know this is possible to do with HQL but is it currently supported
in Linq to NHibernate?
Thanks, Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---