简体   繁体   中英

Entity States in a web application and in a desktop application

When we're using Entity Framework, an entity maybe in one of the following states: Added, Unchanged, Modified, Deleted or Detached. In a desktop application, state changes are typically set automatically but in a web application we have to manually set the entity state.

I want to know why?

Normally, the state of entities is tracked by Entity Framework.

In web applications however, when an entity is retrieved from the database, it gets sent to the browser and Entity Framework can no longer "see" the entity and it can no longer track any changes made to it.

Therefore you would have to manually tell Entity Framework if an entity coming in from a web request (ex. from a form post) should be treated as a new one (and should be inserted) or if it corresponds to an existing entity on the database (and should be updated) or if it should be deleted.

需要跟踪更改,找出更改的附加实体值,以及实体框架应对该附加实体执行的操作。对于分离的实体,手动设置状态很重要,但并非始终如此,如果您需要更多详细信息,则应该就此问题发表一些查询或示例代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM