What does this mean in nhibernate. Can anyone give me a small example?Can someone give me an example of
Restrictions.Disjunction().Add(Subqueries.WhereValue(1).Eq(subquerycount)..
What do these @p3, @p7 do?
select a1, a2 from table1
inner join table2
where (
@p3 = (select count(somevariable)
from t1)
or
table2.isspecific = 0
and @p7=(Select count...)
I'm assuming
subquerycountis a detached Criteria or QueryOver. With that in mind:Restrictionsclass is a helper class for building... well, restrictions. These are translated by NHibernate into theWHEREportion of the SQL query that's ultimately generated.Disjunctionmethod is a helper method that creates a disjunction. In this context, that's an arbitrary number of conditions joined together withOR. There's alsoRestrictions.Conjunction()which generates a conjunction, which is the same thing except joined together withAND.This is what's creating the SQL in the
WHEREclause that you posted. Specifically theORpart:The next portion:
We're saying "Take this disjunction and add a condition to it". We're basically adding an expression that will be
OR'd with other expressions (if any).The expression we're adding (
Subqueries.WhereValue(1).Eq(subquerycount)) is (probably) equal to this bit in the SQL:Hopefully that helps explain what the line in question was doing.
NHibernate generates parameterized SQL. When you supply a value (like "1" in your example), that gets sent to the database in the form of a parameter. The
@p0 ... @pnvalues you see in the generated SQL are just parameters that are auto-generated by NHibernate for you.In your example, I'm guessing
@p3gets assigned to1.