New Posts New Posts RSS Feed: EntityAspect Changes in 6.1.3.1
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

EntityAspect Changes in 6.1.3.1

 Post Reply Post Reply
Author
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post Topic: EntityAspect Changes in 6.1.3.1
    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!


Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down