views:

13

answers:

1

I have a component which contains a collection. I can't seem to get NHibernate to persist items in the collection if I have the collection marked as Inverse. They will persist if I don't have Inverse on the collection, but I get an insert and then an update statement.

My mapping is :

m => m.Component(x => x.Configuration, c =>
{
  c.HasMany(x => x.ObjectiveTitleTemplates)
    .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
    .AsSet()
    //.Inverse()
    .KeyColumns.Add("ObjectiveProcessInstanceId")
    .Cascade.AllDeleteOrphan();                                                               
});

Is there a way to get it working marking the collection as Inverse and therefore avoiding the extra insert?

Thanks!

A: 

Mapping the collection as inverse is not enough. You have to:

  • Create a Reference from the "Many" side
  • Update it when adding elements to the collection

When you use Inverse, NHibernate does not persist the relationship from that side.

Diego Mijelshon