1

I am working on a query in NHibernate in which user could provide a sorting order for some selected fields. I need to do a OrderBy() in QueryOver with the names of field names in entities, but when using projection list I am getting like this.

SELECT
     this_.Number as y0_,
     scc3_.Code as y1_,

FROM sometable
WHERE 1=1 ORDER BY this_.Number as y0_,
 scc3_.Code as y1_ asc

The projection list for select columns is different from orderby projection list and I am not using .WithAlias()

sortProjectionList.Add(Projections.Property(() => stock.Number));
sortProjectionList.Add(Projections.Property(() => scc.Code));

How can I create a projectionlist without aliases or aliases with custom names?

Thanks

4

1 回答 1

1

我希望,您在ORDER BYin case 中遇到生成的关键字“AS”的问题,您传递这样的预测:

// NHibernate will leave few AS, except the last
query.OrderBy(sortProjectionList).Asc();

为了避免这种情况,我们可以这样做:

// NHibernate will solve each projection separately
for (var index = 0; index < sortProjectionList.Length; index++)
{
    query.OrderBy(sortProjectionList[index]).Asc();
}
于 2015-03-15T06:31:54.207 回答