NHibernate OrderBy a correlated subquery -
i have parent
has collection of property
. each property
has propertyclass
, value
. want return list of parent
ordered value
of attached attached property
given propertyclass
let's parent
represents car, there exists property
propertyclass
"color". want return list of cars ordered value of "color" property.
in straight sql, easy, order correlated subquery.
select * [parent] order (select [value] [property] [propertyclass] = 'color' , [parentid] = [parent].[id])
but not know how accomplish @ in nhibernate.
i've gotten far creating subquery projection , setting order-by of query using it:
var dc = detachedcriteria.for<core.property>() .add(restrictions.eq("propertyclass", sortbyproperty)) .setprojection(projections.property("value")); var query = basequery.orderby(projections.subquery(dc));
but order-by clause generated misses correlated subquery part- [parentid] = [parent].[id]
, invalid sql. how make subquery correlated base query?
figured out.
core.property propalias = null; basequery.joinalias(parent => parent.properties, () => propalias) .where(() => propalias.propertyclass == sortbyproperty); var query = basequery.orderby(() => propalias.value);
Comments
Post a Comment