I tried to upgrade NH 3.3.1.4000 to the latest version NH 4.0.2.4000 and I had an issue with FetchMany and ThenFetchMany.
In this post I learned that this old functionality is no longer valid, Breaking changes with NHibernate 4 upgrade.
What is the correct way to do this kind of fetching on the new NH version?
Code Example:
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();
Classes:
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;}
}
Mapping:
<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>