如何在nhibernate中选择孙子实体列表

时间:2014-09-16 12:32:32

标签: nhibernate queryover selectlist grandchild

我有以下实体:国家,州城市。顺便说一下,我在论坛上看到了很多对我没用的例子。 我需要使用WithAlias对这些结果进行投影。如何使用QueryOver检索这些结果?

public class ContryDTO{
   public virtual int id {get;set};
   public virtual string name {get;set};
   public virtual IList <StateDTO>States {get;set};

}

public class StateDTO{
   public virtual int id {get;set};
   public virtual string name {get;set};
   public virtual IList <CityDTO>Cities{get;set};
}



public class CityDTO{
   public virtual int id {get;set};
   public virtual string name {get;set};
}
到目前为止我的查询是:

ReportDTO report = null; CityDTO cities = null; StateDTO states = null;

var result = _session.QueryOver<ContryDTO>()
    .JoinAlias(a => a.name, () => ReportContry )
    .JoinAlias(() => States.Cities, () => ReportCities)
    .SelectList(sl => sl
      .Select(s => s.name).WithAlias(() => rel.nameContry)
      .Select(() => states.name).WithAlias(() => rel.nameSate))

    .TransformUsing(Transformers.AliasToBean(typeof(ReportDTO ........

这个查询有效,但我想带来城市的结果。 我试过SelectList,FecthMany,SelectMany ....但是没有用。我该怎么办?

该论坛的其他不起作用的示例:

Nhibernate exception when ordering entities by grandparent property when eager loading

Fetch vs FetchMany in NHibernate Linq provider

0 个答案:

没有答案