Is there such a thing as a "Nop" ICriterion ? (as in no operation)
I am also having issues trying to understand how to get a row count projection COUNT(*) as I only want the count value out of the query. The following code does not compile as I am not specifying I want RowCountProjection correctly and google is not being my friend today (I cant find a single working example so far for NHibernate, just plenty of API docs with no examples :( ).
I want to optionally add ICriterion into a statement depending upon the callers requested configuration, like the following:
Code:
ICriterion foobarOptionalOne = Expression.Nop();
if(someConditionOne)
foobarOptionalOne = Expression.Eq("EntityPropertyOne", 42);
ICriterion foobarOptionalTwo = Expression.Nop();
if(someConditionTwo)
foobarOptionalTwo = Expression.Eq("EntityPropertyTwo", 42);
Int32 c = session.CreateCriteria(typeof(MyClass))
.SetProjection(new RowCountProjection() /* EUH ??? */ )
.Add(Expression.Eq("FixedRequirement", 99)
.Add(foobarOptionalOne)
.Add(foobarOptionalTwo)
).UniqueResult<int>();
From looking at the source and documentation it does not seem allowed to call .Add(null) which is why I'm wanting to know if there is a Expression.Nop() placeholder ?
TIA!