Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Entity Lifecycle

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 345
    Comment on it

    Entity Lifecycle in EntityFrame Work:--

    Before working on entity framework on asp.net, It's important to know the entity (like any table, list etc.) life cycle and how it is managed by the entity framework. During entitys lifetime, each entity has an entity state based on the operation performed on it via Context(dbcontext, objectContext). The entity state is an enum of type System. Data. Entity State that declares the following values: 

    • Added
    • Deleted
    • Modified
    • Unchanged
    • Detached

    In Entity framework the context holds the reference of the all objects those are retrieved from database. The context also responsible for entity states and maintains modifications to the properties of the entity. This is called Change Tracking. 

    In entity framework the Unchanged to the modification state automatically handled by the context.Below figure illustrate how the operation performed in entity and which state is turns.
    alt text

    1. AddObject - AddObject is used to Adds an entity to the context. It's entity state is 'Added'.
    2. Attach - The entity state is unchanged when Attaches an entity to the context.
    3. ApplyCurrentValues - Replace currently attached entitys scalar value with the current property values of detached entity. It's entity state is 'Modified'.
    4. ApplyOriginalValues - It applies original database values to attached entitys properties. It's entity state is 'Unchanged'.
    5. DeleteObject - Delete the object from context. It's entity state is 'Deleted'.
    6. AcceptAllChanges - Update the current values of every attached entity into the original values. It's entity state is 'Unchanged'.
    7.  ChangeState or ChangeObjectState - Change an entity from one state to another without any restrictions (except for Detached). It's entity state is 'Based on passed state'.
    8.  Detach - Removes an entity from the context. It's entity state is 'Detached'.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: