how to force nhibernate to set the foreign key of the child item?
Posted
by npeBeg
on Stack Overflow
See other posts from Stack Overflow
or by npeBeg
Published on 2010-04-07T14:22:43Z
Indexed on
2010/05/20
20:20 UTC
Read the original article
Hit count: 172
i have a collection in the mapping:
<bag name="Values" cascade="all-delete-orphan" lazy="false" inverse="true">
<key column="[TemplateId]"/>
<one-to-many class="MyNamespace.Value, MyLib"/>
</bag>
the Value object has a foreign key [TemplateId]. both entities has their generator set to "identity". when i call session.Save() for the parent Template object, the Value objects has their [TemplateId] (the foreign key) set to zero, so an SQL exception appears. how do i forse nhibernate to set the FK value for the child items to the value of the inserted parent object?
© Stack Overflow or respective owner