NHibernate:ProjectionList:我们可以为 Orderby 创建动态投影列表吗
NHibernate: ProjectionList: Can we create dynamic projectionlist for Orderby
我正在 NHibernate 中进行查询,用户可以在其中为某些 selected 字段提供排序顺序。我需要在 QueryOver 中使用实体中的字段名称执行 OrderBy()
,但是在使用投影列表时我会这样。
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
select 列的投影列表与 orderby 投影列表不同,我没有使用 .WithAlias()
sortProjectionList.Add(Projections.Property(() => stock.Number));
sortProjectionList.Add(Projections.Property(() => scc.Code));
如何创建没有别名或带有自定义名称的别名的投影列表?
谢谢
我希望您在 ORDER BY
中遇到生成关键字 "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();
}
我正在 NHibernate 中进行查询,用户可以在其中为某些 selected 字段提供排序顺序。我需要在 QueryOver 中使用实体中的字段名称执行 OrderBy()
,但是在使用投影列表时我会这样。
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
select 列的投影列表与 orderby 投影列表不同,我没有使用 .WithAlias()
sortProjectionList.Add(Projections.Property(() => stock.Number));
sortProjectionList.Add(Projections.Property(() => scc.Code));
如何创建没有别名或带有自定义名称的别名的投影列表?
谢谢
我希望您在 ORDER BY
中遇到生成关键字 "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();
}