| 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;
}
} |