说我有一个类似的查询:
return NHibernateHelper.Session.QueryOver<SomeEntity>()
.JoinQueryOver(x => x.Entity2)
.JoinQueryOver(x => x.Entity3)
.Where(x = x.Id > 10)
.OrderBy( ???? )
.List<SomeEntity>();
现在说我想通过Entity3.SortOrder专栏订购,我怎么能这样做?
答案 0 :(得分:3)
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>();