Nhibernate / Queryover: How To Left Join With Parameter
Is there a way in NHibernate / QueryOver API to pass a parameter already in the mapping (so it uses the parameter as a fixed value for all queries on this particular instance). I n
Solution 1:
You can add a condition to a join
clause using the overload of JoinQueryOver
or JoinAlias
that takes a withClause
parameter. For example:
SomeTable stAlias = null;
session.QueryOver<ProblematicView>()
.Left.JoinAlias(
pv => pv.SomeTable, // Join path() => stAlias, // alias assignmentst => st.SomeOtherValue == 123) // "with" clause/* etc. */
The "with" portion of the QueryOver join is what will add a condition to the left outer join
in SQL. The above should generate this:
SELECT/* select list */FROM [ProblematicView] this_
leftouterjoin [SomeTable] sometable1_
on this_.Id = sometable1_.ProblematicViewId
and (sometable1.SomeOtherValue =123/* @p0 */)
If I understand correctly, this should help solve your problem.
A few things to note about adding a "with" clause:
- Interestingly, all of the overloads of
JoinQueryOver
andJoinAlias
that allow you to specify a "with" clause require that you assign an alias when you do the join. - You cannot (as far as I know) generate SQL with an
or
in the join condition. the "with" clause is alwaysand
ed with the mapped join condition (i.e., FK → PK)
Post a Comment for "Nhibernate / Queryover: How To Left Join With Parameter"