我正在使用 NHibernate 和 FluentNH。
以下是四门课。
表单类型
public class FormType
{
public virtual int Id
{ get; set; }
public virtual string Name
{ get; set; }
public virtual IList<KeyCompetency> KeyCompetencies
{ get; set; }
}
关键能力
public class KeyCompetency
{
public virtual int Id
{ get; set; }
public virtual string Name
{ get; set; }
public virtual FormType FormType
{ get; set; }
public virtual IList<SubCompetency> SubCompetencies
{ get; set; }
}
子能力
public class SubCompetency
{
public virtual int Id
{ get; set; }
public virtual string Name
{ get; set; }
public virtual KeyCompetency KeyCompetency
{ get; set; }
public virtual IList<Ability> Abilities
{ get; set; }
}
能力
public class Ability
{
public virtual int Id
{ get; set; }
public virtual string Description
{ get; set; }
public virtual SubCompetency SubCompetency
{ get; set; }
}
我正在尝试加载基于 id 的表单类型。
using (var session = DataContext.OpenSession())
{
return session.Query<FormType>()
.Where(x => x.Id == 1)
.FetchMany(x => x.KeyCompetencies)
.ThenFetchMany(x => x.SubCompetencies)
.ThenFetchMany(x => x.Abilities)
.ToList().FirstOrDefault();
}
我收到重复的关键能力、子能力记录。