Hi,
Probably a stupid question but I'm still trying to wrap my head around nHibernate.
As far as I can tell from using the software, nHibernate requires you to do a little bit of extra handling for saving changes properly.
Let's imagine I have an object X which can contain many of object Y. I'll create an X which has 2 Y's, each of which have their own properties. I then decide I want to update X. I'm going to add a new Y, and change one of the existing Y's.
So I load in my object X using it's ID. I then iterate through the Y's that I'm adding, add them to the X and save the lot using an update statement.
If you do this, you find the "old" Y's get orphaned in the database. Which, when I think about it, is exactly what I'd expect to happen - I haven't got rid of those objects after all, I've just created some new ones.
So there's two ways to look at this. Either I ought to be deleting all the Y data and then re-creating it, or I ought to be able to flag up to nHibernate that what I'm doing is a change and that it should be updating existing objects rather than creating new ones. Trouble is, I'm not sure which is the "right" approach or how best to do it - the former seems tremendously inefficient and the latter means setting a lot of "changed" flags and very fiddly code.
So I'm pretty sure there must be an easier solution that I'm missing in my stupidity. Can someone point me at the best approach and how best to handle it in nHibernate ... that is if the question makes any sense at all :)
Cheers, Matt