Entity Framework 4 Save and Cancel
I'm currently testing the entity framework 4 for a simple app I wish to build.
I've searched high and low for the answer to this without any luck!!
My question is how do you save and cancel changes on a record basis? Using the save changes method on the context persists all the changes to the database. Is there a way to control this?
Thanks Gary
You shouldn't use a singular Data Context for all the operations in the lifetime of your application. Spin up a session (create a Data Context) for each atomic operation you want to make. Call SaveChanges to submit the operation, simply dispose of the context without saving changes to 'cancel' the operation.
Sounds like you want to work in a disconnected fashion.
You might also want to look into different EF templates such as self tracking entities which may make your life a bit easier as they generate entities which can track changes themselves outside of a data context; however this might be overkill for a simple app.
链接地址: http://www.djcxy.com/p/33562.html上一篇: 实体框架超时
下一篇: 实体框架4保存并取消