Print Page | Close Window

EntityAspect Changes in 6.1.3.1

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3128
Printed Date: 18-Oct-2025 at 9:23am


Topic: EntityAspect Changes in 6.1.3.1
Posted By: chuckc
Subject: EntityAspect Changes in 6.1.3.1
Date Posted: 06-Dec-2011 at 3:00pm

As of 6.1.3.1 there appear to be some different behaviors introduced regarding EntityState at various points in an entity lifecycle.  Previously, an entity was UnChanged at create time – now it is Detached, and does not have an EntityAspect.EntityManger defined.  Below is a snippet of code where I was using EntityAspect.EntityManager for a NullEntity, and the changes I made to deal with the new behavior in 6.1.3.1.

public Contact Contact
{
   get
   {
      if (this.EntityAspect.IsNullEntity)
      {
         // 6.1.3.1 return this.EntityAspect.EntityManager.GetNullEntity<Contact>();
         // 
this.EntityAspect.EntityManager is now null here.
         return myEntityManager.MyDefaultManager.GetNullEntity<Contact>(); // 6.1.3.1
       }
       // Otherwise, get and return a Contact using custom logic…
  }
}

 My questions are:  
What was the reason for this change?  
Is there some other recommended way to accomplish what I’m doing without resorting to a “default entity manager”?  
Do you see any likely problems with using this “default” entity manager  approach

I’ve also noticed that now an entity becomes Detached after it’s saved.  Previously it remained attached to it’s entity manager and was just set to UnChanged.  What was the rationale for this change in behavior?  If I just re-attach an entity after saving (as below), what sort of side-effects should I watch out for?

_entityManager.SaveChanges(new EntityBase[] { entity });
_entityManager.AttachEntity(entity); // fix for version 6.1.3.1


 Thanks!





Replies:
Posted By: kimj
Date Posted: 08-Dec-2011 at 11:51am
There have been several changes to entity handling over the releases this year.  Which version of DevForce were you using prior to 6.1.3.1? 
 
We did rationalize the behavior between creating an entity via CreateEntity and newing an entity.  In both cases the entity is always Detached until added to an EntityManager.  If actually added (via AddEntity or AddToManager) then it's state will then become Added; if it was instead attached (via AttachEntity) then it's state will become Unchanged.
 
The Detached entity state means that the entity does not have an EntityManager.  The null entity for an entity type is a kind of sentinel, it is always Detached and therefore never has an EntityManager.   Your workaround for this change is reasonable;  since you have a "myEntityManager" handy, you could call GetNullEntity on that instead if you wanted.
 
An entity should never become detached after a save, unless it's previous state was Deleted.  If you find this happening for inserts and updates then that could be a bug, and we'd need more information.  After a successful save, all saved entities with a previous state of Added or Modified should now have an Unchanged state.
 



Print Page | Close Window