NHLambdaExtensions: Create a Criterion object to add to ICriteria later

落花浮王杯 提交于 2019-12-08 02:15:18

问题


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:


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

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


来源:https://stackoverflow.com/questions/1809247/nhlambdaextensions-create-a-criterion-object-to-add-to-icriteria-later

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!