简体   繁体   English

使用NHibernate StatelessSession级联集合

[英]Cascading collections using NHibernate StatelessSession

What is the proper way to bulk insert entities which contain collections of other entities (a HasMany mapping), using stateless sessions? 使用无状态会话批量插入包含其他实体集合( HasMany映射)的实体的正确方法是什么?

Eg Parent class is mapped like this: 例如,父类的映射如下:

class ParentMap : ClassMap<Parent>
{
    public ParentMap()
    {
        Id(x => x.Id)
           .GeneratedBy.Increment();

        HasMany(x => x.ChildNodes)
           .KeyColumns.Add("Parent_id")
           .Cascade.All();
    }  
}

Stateless session ignores the Cascade option, so child nodes are not persisted automatically. 无状态会话将忽略Cascade选项,因此子节点不会自动持久化。 I could iterate through the collection myself, but then I cannot set the relation, because Parent_id column does not exist as a property I could write to. 我可以自己遍历该集合,但是之后我无法设置该关系,因为Parent_id列不作为我可以写入的属性而存在。

Am I missing something? 我想念什么吗?

您必须在子类中创建Parent属性,或者使用有状态会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM