假设我有一个类似的查询:

return NHibernateHelper.Session.QueryOver<SomeEntity>()
    .JoinQueryOver(x => x.Entity2)
    .JoinQueryOver(x => x.Entity3)
    .Where(x = x.Id > 10)
    .OrderBy( ????  )
    .List<SomeEntity>();


现在说我想按Entity3.SortOrder列进行订购,我该怎么做?

最佳答案

Entity2 e2Alias = null;
Entity3 e3Alias = null;
SomeEntity s = null;
return NHibernateHelper.Session.QueryOver<SomeEntity>()
    .JoinAlias(() => s, () => e2Alias.SomeEntityReference) //here you need to specify the other  side of the relation in the other entity that refernces th SomeEntity
    .JoinAlias(() => s, () => e3Alias.SomeEntityReference)
    .Where(() => s.Id > 10)
    .OrderBy( () => e3Alias.SortOrder).Asc //or Desc
    .List<SomeEntity>();

关于c# - 如何使用QueryOver内部联接按列排序?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7839000/

10-11 12:02