Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fluent nhibernate Fluent Nhibernate获取具有填充子集合的对象_Fluent Nhibernate - Fatal编程技术网

Fluent nhibernate Fluent Nhibernate获取具有填充子集合的对象

Fluent nhibernate Fluent Nhibernate获取具有填充子集合的对象,fluent-nhibernate,Fluent Nhibernate,我有 映射 public class Parents { public Parents() { Childs = new HashedSet<Childs>(); } public virtual int Id {get; set;} public virtual String Name {get; set;} public virtual ISet<Childs> Childs {get; protected se

我有

映射

public class Parents {
    public Parents() {
        Childs = new HashedSet<Childs>();
    }
    public virtual int Id {get; set;}
    public virtual String Name {get; set;}
    public virtual ISet<Childs> Childs {get; protected set;} 
}

public class Childs {
    public virtual int Id {get; set;}
    public virtual String Name {get; set;}
    public virtual Parents Parent {get; set;}
}
如何使用Link、HQL或AutoMapper来选择有孩子的家长?例如,在我的测试用例中有这样的查询

....
.Override<Parents>(map => {
    map.HasMany(x => x.Childs).KeyColumn("parent_id").Cascade.SaveUpdate().Not.LazyLoad().AsSet().Fetch().Join();
})
 .Override<Childs>(map => {
      map.References(x => x.Parent, "parent_id");
})
....

在日志中,我看到query:select with join,但我只得到不带childs的父对象

您需要使childs属性反向


如果它是反向的,则不存储它。在您的测试用例中,列表为空—您不将子项添加到父项,您只将子项中的back引用设置为父项。如果它被存储,它现在正在做什么,NH将清除数据库中的列表并从父项中删除子项。

我知道了。这是因为一次会议。我需要阅读有关使用会话的文档。但是你能提供一个链接让我读到它吗:如果它被存储了,它现在在做什么,NH会清除数据库中的列表,并从父代码或者NH代码的一部分中删除子代码,因为我检查了它,它不是真的
Parents parent = new Parents {Name = "parent test"};
Childs child   = new Childs {Name = "child test", Parent = parent};
session.Save(parent);
session.Save(child);
...
var myParent = session.QueryOver<Parents>().Where(x=>x.Id==1).List()[0];
Assert.IsTrue(myParent.Childs.Count>0);
...