How to use transactions with the Entity Framework?

前端 未结 5 505
说谎
说谎 2020-12-13 13:47

When you have code like this:

Something something = new Something();
BlahEntities b = new BlahEntities()    
b.AddToSomethingSet(something);
b.SaveChanges();         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 14:37

    In all versions of Entity Framework, whenever you execute SaveChanges() to insert, update or delete on the database the framework will wrap that operation in a transaction. This transaction lasts only long enough to execute the operation and then completes. When you execute another such operation a new transaction is started. For Newest Entity Framework version: 6.0 +

    Read More Here: EntityFramework and Transaction

提交回复
热议问题