vgru
vgru

Reputation: 51244

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?

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?

Upvotes: 7

Views: 2044

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

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

Upvotes: 6

Related Questions