-1

エンティティ フレームワークで savechages() 関数を呼び出すと、エンティティの現在の値と元の値が比較され、データベースが更新されます。あれは正しいですか?。もう1つ疑問があります。上記の条件が正しい場合、作成操作でsavechanges()を呼び出す必要はありますか?. 作成操作でそれを呼び出す理由。

 www.google.com
4

1 に答える 1

1

についてあなたが言ったことは本当です。変更を保存してSaveChanges()it check if the entity is in modified stateデータベースに反映できるようにします。

作成操作の場合はcreate a new object and add that to your entity、ここでもentity state is modifiedsavechanges() を呼び出す必要があります。

変更内容を保存()

An entity can be in one of five states as defined by the EntityState enumeration. These states are:

Added: the entity is being tracked by the context but does not yet exist in the database
Unchanged: the entity is being tracked by the context and exists in the database, and its property values have not changed from the values in the database
Modified: the entity is being tracked by the context and exists in the database, and some or all of its property values have been modified
Deleted: the entity is being tracked by the context and exists in the database, but has been marked for deletion from the database the next time SaveChanges is called
Detached: the entity is not being tracked by the context



SaveChanges does different things for entities in different states:

Unchanged entities are not touched by SaveChanges. Updates are not sent to the database for entities in the Unchanged state.
Added entities are inserted into the database and then become Unchanged when SaveChanges returns.
Modified entities are updated in the database and then become Unchanged when SaveChanges returns.
Deleted entities are deleted from the database and are then detached from the context.
于 2013-10-11T04:07:50.610 に答える