我有以下实体:
public class Parent
{
public string Id { get; set; }
public Ilist<Child> Children { get; set; }
}
public class Child
{
public string Id { get; set; }
public Ilist<Parent> Parents { get; set; }
public Ilist<Grandchild> GrandChildren { get; set; }
}
public class Grandchild
{
public string Id { get; set; }
public Child parent { get; set; }
}
他们的映射:
public class ParentMap
{
HasManyToMany(x => x.Children).Table("P_C").LazyLoad();
}
public class ChildMap
{
HasManyToMany(x => x.Parent).Table("P_C").Inverse();
HasMany(x => x.Parents).KeyColumn("ParentID").Cascade.All().Inverse();
}
public class GrandchildMap
{
References(x => x.parent).Column("ParentID").Not.Nullable();
}
我想使用NHibernate 4获取所有级别的Eager 当我尝试通过ID获取单个父母时:
var Parent = session.QueryOver<Parent>().Where(x => x.Id == Id).
Fetch(x => x.Children).Eager.
Fetch(x => x.Children.First().GrandChildren).Eager.
TransformUsing(Transformers.DistinctRootEntity).
List<Parent>().FirstOrDefault();
我得到“无法同时获取多个行李”异常