Login Skip Navigation LinksWilsonORMapper > Forums Search
Demo Version Demo Version
Download and try for yourself a fully working demo version, including sample apps and documentation.  The only limitation is that the demo version only works inside the debugger.

PayPal Subscribe
Get It All for $50 USD:
WebPortal, ORMapper,
Source Code, All Updates
PayPal

User Login User Login
Log In
 
 
Reset Password

Wilson ORMapper Forums Wilson ORMapper Forums : Advanced Topics : Navigate ManyToOne relations when persisting with PersistDepth.ObjectGraph.

Date Post
5/3/2006 6:06:13 PM

Hi Paul,

I have object A referencing object B, but possibly more than one A instance reference a single B instance. So this is a many to one relation ship (and one could say B is the parent of A, though this feels unnatural since A is my 'root' object referencing other objects). Anyways, my "problem" is that when storing object A with PersistDepth.ObjectGraph, I'd intuitively expect that A is stored, and also B is stored. However, it seems that because B is viewed as the parent, the graph is not navigated 'upwards', and B is not stored. However, when taking the viewpoint that all tracable references as seen from A, I'd say that B should also be stored. That other A's are also referencing B should be of no concern, B has no references to A, so that's where the persisting should end.

Kind regards,

Wout

E-mail: wout at woutware dot com

 

5/3/2006 6:15:59 PM Hi Wout:

I realize that there are cases where people feel like the many-to-one object should also be saved, but in my experience that is rare and is also prone to cause other problems since as you note there can be multiple objects referencing the say many-to-one object.  So for better or worse I have defined the an object graph as referring to a root object and its mapped one-to-many and many-to-many collections.  Even with the many-to-many it actually only saves the "linkings" and not the actual objects on the other side of the many-to-many.  This is pretty consistent with some other mappers, although I cannot claim to know if there are others that do something more or not -- but I do believe there are a lot of potential issues should some do more.

So what are the alternatives?  In some cases you can consider the many-to-one object your root object, but that won't work in many cases.  The other recommendation I have is to use an explicit transaction -- see ObjectSpace.BeginTransaction and then call Transaction.PersistChanges for both your root and any many-to-one objects that are changed, followed of course by Transaction.Commit.  Its a little more work, but it should be relatively easy to include in your application if this scenario is something your application allows.

Thanks, Paul Wilson
5/30/2006 12:05:54 AM

Hi Paul,

That's what we're doing now, and it works.

Thanks,

Wout