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!