List プロパティの QueryOver の JoinAlias と SelectList を使用して、Nhibernate でプロジェクションを構築する際に問題があります。
IList プロパティ PageHeaders を持つドメイン オブジェクト PageRic があります。
public class PageRic: AuditableLegacy
{
public virtual string Ric { get; set; }
public virtual McdDistId McdDistId {get; set; }
public virtual IList<PageHeader> PageHeaders { get; set; }
public virtual string Pointer { get; set; }
public virtual bool Dup { get; set; }
public virtual int Throttle { get; set; }
}
PageHeaders プロパティは HasMany としてマップされます。
public class PageRicMapping : ClassMap<PageRic>
{
public PageRicMapping()
{
Table("PAGE_RICS");
Id(x => x.Ric, "RIC").Not.Nullable();
References(x => x.McdDistId, "MCD_DIST_ID")
.Not.LazyLoad()
.Nullable();
HasMany(x => x.PageHeaders)
.KeyColumn("RIC")
.Fetch.Subselect()
.Inverse()
.Cascade.AllDeleteOrphan()
.Not.LazyLoad();
Map(x => x.Pointer, "POINTER");
Map(x => x.Dup, "DUP").Not.Nullable().CustomType<YesNoType>();
Map(x => x.Throttle, "THROTTLE");
}
}
このクエリを実行すると:
PageRicDTO pageRicDTO = null;
McdDistId McdDistAlias = null;
var results = Session.QueryOver<PageRic>()
.JoinAlias(x => x.McdDistId, () => McdDistAlias)
.SelectList(list => list
.Select(x => McdDistAlias.Id).WithAlias(() => pageRicDTO.McdDistId)
.Select(x => McdDistAlias.ShortName).WithAlias(() => pageRicDTO.McdDistName)
.Select(x => x.Ric).WithAlias(() => pageRicDTO.Ric)
.Select(x => x.Throttle).WithAlias(() => pageRicDTO.Throttle)
.Select(x => x.Rowstamps).WithAlias(() => pageRicDTO.Rowstamps)
.Select(x => x.PageHeaders).WithAlias(() => pageRicDTO.PageHeaders)
)
.TransformUsing(Transformers.AliasToBean<PageRicDTO>())
.List<PageRicDTO>();
IndexOutOfRangeException が発生します: インデックスが配列の範囲外でした。ログファイルには次のように表示されます。
2012-04-18 15:00:38,823 [CurrentAppDomainHost.ExecuteNodes] DEBUG NHibernate.SQL - y0_ として mcddistali1_.MCD_DIST_ID、y1_ として mcddistali1_.SHORT_NAME、y2_ として this_.RIC、y3_ として this_.THROTTLE、y4_ として this_.ROWSTAMPS を選択します。 , this_.RIC as y5_ FROM PAGE_RICS this_ inner join MCD_DIST_IDS mcddistali1_ on this_.MCD_DIST_ID=mcddistali1_.MCD_DIST_ID
2012-04-18 15:00:39,306 [CurrentAppDomainHost.ExecuteNodes] WARN NHibernate.Util.ADOExceptionReporter - System.IndexOutOfRangeException: インデックスが配列の範囲外でした。NHibernate.Loader.Criteria.CriteriaLoader.GetResultColumnOrRow(Object[] 行、IResultTransformer resultTransformer、IDataReader rs、ISessionImplementor セッション) で NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet、ISessionImplementor セッション、QueryParameters queryParameters、LockMode[] lockModeArray、EntityKey optionalObjectKey 、IList hydredObjects、EntityKey[] キー、Boolean returnProxies) の NHibernate.Loader.Loader.DoQuery(ISessionImplementor セッション、QueryParameters queryParameters、Boolean returnProxies) の NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor セッション、QueryParameters queryParameters、
.Select(x => x.PageHeaders).WithAlias(() => pageRicDTO.PageHeaders)をコメントアウト すると、DTO オブジェクトが取得されます。
この問題の解決策を教えてください。