NHLambdaExtensions: Create a Criterion object to add to ICriteria later

220 Views Asked by At

My application creates a dynamically generated query at runtime based on user input by creating Criterion objects e.g:

ICriterion criterion = Restrictions.Eq("Name", "John");
......
detachedCriteriaSomewhereElse.Add(criterion);

How do I do this in NHLambdaExtensions?

what I really need to do is

ICriterion criterion = Restrictions.Eq<Person>(p=>  p.Name == "John");

but this isn't valid. Is there any way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

With the NHLambdaExtensions you have the SQLExpression class that lets you do the following:

ICriterion criterion = SqlExpression.CriterionFor<Person>(p => p.Name == "John");