I have x , which is an object of type objectX , which has a ListOfObjectYs property, which
List<objectY>
nhibernate mapping is as follows:
public ObjectXMap() { HasMany(x => x.ListOfObjectYs).AsBag().Inverse(); }
when I go to save it, I change some properties to objectX , and then:
Session.SaveOrUpdate(x);
Now I need to update this property, which is a list. I get a new list of objectYs, and I want to replace the existing list of objectsY with a new list. do i need to do this?
foreach (ObjectY y in x.ListOfObjectYs) { Session.Delete(y); deleted = true; } if (deleted) { _session.Flush(); } x.ListOfObjectYs.Clear(); foreach (ObjectY y in newObjectYList) { x.ListOfObjectYs.Add(y); Session.SaveOrUpdate(y); } _session.Flush();
my questions:
- Do I need to delete everything and erase before adding new ones.
- Do all these incremental savings need to be done between
there is a better way to do this update where I need to update the object (s) and also update the properties that are listed where there is a whole new list (this means that the elements need to be removed and added).
c # asp.net-mvc nhibernate fluent-nhibernate
leora
source share