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 : Feature Requests : Assume insert if not tracked

Date Post
5/26/2006 6:12:46 PM

Hi Paul,

I made a change to the Context class to help me avoid having to track wheter StartTracking had been called on each object.  Basically, I think it is OK for me to assume that if StartTracking had not been called, then it is an insert.  The assumption is made that the same instances hash table is used for selects and inserts.  I am working a solution for this in a remoted environment... but that is another story.

I can continue to make this change in new ORMapper versions...  but I thought I'd try to get a 'sanctioned' version of this change into the main code line.

For what it is worth, I believe NHibernate uses this approach.

Thanks,

- Doug

Here is the change:

public Instance this[object entityObject] {

get {

   // Jeff Lanning (jefflanning@gmail.com): Made thread-safe (and improved performance a bit).

   EntityKey entityKey = new EntityKey(this, entityObject, true);

   Instance instance = (Instance)this.instances[entityKey];

   if (instance == null) {

      // HERE IS THE CHANGE: assume tracking an insert instead of throwing

      this.StartTracking(entityObject, InitialState.Inserted);

      entityKey = new EntityKey(this, entityObject, true); // guid keys get assigned at start tracking

      instance = (Instance)this.instances[entityKey];

      //END OF CHANGE     

      // throw new ORMapperException("ObjectSpace: Entity Object not being Tracked - " + entityKey);

   }

   instance.EntityObject = entityObject; // Refresh WeakReference

   return instance;

   }

}

5/26/2006 6:14:44 PM I'm looking at a few cases similar to this, but I haven't done enough yet to promise this specific case.

Thanks, Paul Wilson