我有以下映射:
<class name="Entity, Namespace.MyDomain" table="Entity" lazy="false" mutable="false" >
<id name="EntityId" column="ENTITY_ID"> <generator class="native"/> </id>
<bag name="EntityList" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="ENTITY_ID"/>
<one-to-many class="Namespace.Entity.EntityList, Namespace.MyDomain"/>
</bag>
现在,我希望通过我的EntityList.Name获得有序的分页 例如,如果我有2个实体: 1)具有动物名称的实体列表的实体(老虎) 2)具有动物名称的实体列表的实体(猫,狗) 然后,我想先得到第二个实体(因为猫的'c'低于't'的老虎),然后是第一个实体。
当然,它会影响我的分页,因为如果我通过entity.id获取我的分页,那么有可能在第一页上显示带虎的实体,但是当我通过entitylist.names获取它时,它可能会显示在其他页面上。
提前致谢, 麦克
P.S。 - 我正在使用标准。
答案 0 :(得分:0)
var entityIds = session.CreateCriteria<Entity>()
.CreateAlias("EntityList", "el")
.AddOrder(Order.Asc("el.Name"))
.SetProjection(Projections.Id)
.List<int>();
var entities = session.CreateCriteria<Entity>()
.Add(Expression.In(Projections.Id, entityIds))
.SetFetchMode("EntityList", FetchMode.Eager)
.List<Entity>();
// resort again
return entityIds.Select(id => entities.First(e => e.Id == id)).ToList();