Up Create, modify and delete

Change the EntityState

Last modified on August 15, 2012 17:21

This topic identifies many of the things you can do to an entity that change its EntityState.



Operations that change the EntityState

Here's a brief summary of the EntityState-changers you'll run into most frequently:

Operation  Summary
Query  A successful query returns entities that are attached to the EntityManager. A newly-queried entity is Unchanged unless it happens to already be in cache. If the entity is already in cache, it retains its current EntityState by default. See the MergeStrategy topic for details.
AddEntity Attaches the entity to the EntityManager as an Added entity. The entity is presumed to be new and unknown to the database. It would be inserted if saved.
AddToManager()Attaches the entity to an inner, hidden EntityManager as a new entity. Call for an entity you created with EntityManager.CreateEntity(). See the special topic on this method.
AttachEntity Attaches the entity to the EntityManager as an Unchanged entity. The entity is presumed to be in the database already.
RemoveFromManager Detaches the entity from its current EntityManager. The new state is Detached.
Set a property An Unchanged entity becomes Modified. Entities in other states retain their EntityState values.
Save  If the save succeeds, Added and Modified entities become Unchanged. Deleted entities are removed from cache and become Detached
RejectChanges Modified and Deleted entities are rolled back to their pre-change values; their new EntityState is Unchanged. Added entities are removed from the EntityCache and become Detached.
AcceptChanges  As with save, Added and Modified entities become Unchanged. Deleted entities are removed from cache and become Detached. Save actually calls AcceptChanges. Beware: calling AcceptChanges does not save them. Call it with a good reason, e.g., building test and design-time entities.
SetAdded Change the entity from its current, non-Detached, state to the Added state. A feature most useful when building test and design-time entities. 
SetModified Change the entity from its current, non-Detached, state to the Modified state. A feature most useful when building test and design-time entities. 
Tags: EntityState
Created by DevForce on February 22, 2011 12:51

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2020 IdeaBlade