Cascade save on child collections...

0 views
Skip to first unread message

Eric J. Peters

unread,
Jan 22, 2010, 7:57:39 PM1/22/10
to nhusers

Hi-

I'm sure this is a totally rookie question, but I'm not finding the
answer anywhere.

I have an entity with a child collection of other entites, something
like this:

public class Person
{
int? Id { get; set; }
string Name { get; set; }
IList<Vehicle> Vehicles { get; set; }
}

public class Vehicle
{
int? Id { get; set; }
string Name { get; set; }
}

Both sides are mapped (using Fluent NHibernate) as a Reference/HasMany
relationship.

The problem is that when I create an new Person with some new
Vehicles, the save isn't cascading to the Vehicles. If I save the
vehicles first, then apply them to the new Person, it works fine, but
I really want to avoid the extra step of explicitly creating/saving
the Vehicles first.

It seems that this should be something easily achievable with
NHibernate, but I'm not finding the magic handshake. Can anybody
provide me some advice on how to make these objects work as I'm
hoping?

Thanks!
-Eric.

Diego Mijelshon

unread,
Jan 22, 2010, 9:53:12 PM1/22/10
to nhusers
You say that both sides are mapped but I don't see the reference from Vehile to Person.
Once you have that, setting Inverse and Cascade All on the Person side should do the trick.

   Diego



--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.


Reply all
Reply to author
Forward
0 new messages