开发者

NHLambdaExtensions: Create a Criterion object to add to ICriteria later

开发者 https://www.devze.com 2022-12-12 13:00 出处:网络
My application creates a dynamically generated query at runtime based on user input by creating Criterion objects e.g:

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 NHLambdaExten开发者_StackOverflow中文版sions?

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?


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

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

精彩评论

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