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
subquerycount
is a detached Criteria or QueryOver. With that in mind:Restrictions
class is a helper class for building... well, restrictions. These are translated by NHibernate into theWHERE
portion of the SQL query that's ultimately generated.Disjunction
method 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
WHERE
clause that you posted. Specifically theOR
part: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 ... @pn
values you see in the generated SQL are just parameters that are auto-generated by NHibernate for you.In your example, I'm guessing
@p3
gets assigned to1
.