Entity life cycle (EF Basic Series 8)

Source: Internet
Author: User

Before we make additions and deletions, it is important to understand the life cycle of an entity and how it is manipulated by EF.

During the life cycle of an entity, each entity's context-based operations have an entity state, which is the value of an enumerated type: System.Data.Entity.EntityState, which contains the following values:

1.Added

2.Deleted

3.Modified

4.Unchanged

5.Detached

The data context contains not only references to all objects retrieved from the database, but also the entity state of the entity object, which maintains the properties of the modified entity, which is called change tracking.

The change in entity state from "unchaged" to "Modified" is handled automatically by the data context, so other state changes must be made using DbContext and dbset appropriate methods.

The following diagram lists the actions that change the state of the entity, which in turn affects the operation of the database.

A new entity, when saved, is generated by the Insert command;

Querying an entity, the state of the entity is unchanged;

After modifying the entity, save again, that is update;

Remove is Delete

Entity life cycle (EF Basic Series 8)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.