Cascading collections using NHibernate StatelessSession
Asked Answered
P

1

7

What is the proper way to bulk insert entities which contain collections of other entities (a HasMany mapping), using stateless sessions?

E.g. 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. 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.

Am I missing something?

Philibeg answered 25/11, 2010 at 11:45 Comment(0)
M
6

You have to either create the Parent property in the child class, or use a stateful session.

Messer answered 25/11, 2010 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.