【发布时间】:2015-01-26 06:19:45
【问题描述】:
我尝试将 NH 3.3.1.4000 升级到最新版本 NH 4.0.2.4000,但 FetchMany 和 ThenFetchMany 出现问题。
在这篇文章中,我了解到这个旧功能不再有效,Breaking changes with NHibernate 4 upgrade。
在新的 NH 版本上进行这种获取的正确方法是什么?
代码示例:
var IdsList = new List { /* Some Ids */ };
session.Query<A>()
.FetchMany(x=>x.B_ObjectsList)
.ThanFetchMany(x=>x.C_ObjectsList)
.Where(x=>IdsList.Contains(x=>x.Id))
.ToList();
类:
Public Class A
{
public int Id {get;set;}
public IList<B> B_ObjectsList{get;set;}
}
Public Class B
{
public int Id {get;set;}
public IList<C> C_ObjectsList {get;set;}
}
Public Class C
{
public int Id {get;set;}
}
映射:
<class name="A" table="A">
<id name="Id" type="int" column="Id" unsaved-value="0">
<generator class="identity" />
</id>
<bag name="B" table="B" inverse="false" lazy="true"
cascade="all-delete-orphan">
</class>
<class name="B" table="B">
<id name="Id" type="int" column="Id" unsaved-value="0">
<generator class="identity" />
</id>
<bag name="C" table="C" inverse="false" lazy="true"
cascade="all-delete-orphan">
</class>
<class name="C" table="C">
<id name="Id" type="int" column="Id" unsaved-value="0">
<generator class="identity" />
</id>
</class>
【问题讨论】:
标签: c# .net nhibernate nhibernate-4