1

我有以下实体:

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();

我得到“不能同时取多个包”异常

4

0 回答 0