开发者

Transactions with EF

开发者 https://www.devze.com 2023-01-20 22:36 出处:网络
I have 2 questions : i) How can put this code in a transaction ? With ObjectContext in EF, I use开发者_如何转开发 ExecuteStoreQuery() method to start some stored procedure. I have a block of code li

I have 2 questions :

i) How can put this code in a transaction ?

With ObjectContext in EF, I use开发者_如何转开发 ExecuteStoreQuery() method to start some stored procedure. I have a block of code like this :

{
    foreach(...)
    {
     objectContext.ExecuteStoreQuery( @"INSERT MyProcedure (arg1, arg2) VALUES                                 ({0}, {1});", ...);
    }
     // ...
     objectContext.ExecuteStoreQuery( @"INSERT MyProcedure2 (arg1, arg2) VALUES                                 ({0}, {1});", ...);    
 } 

ii) Is possible to commit at the same time ExecuteStoreQuery() calls with object context changes with SaveChanges() ?

My object context is changing in my code. At the end, I have to do a SaveChanges() to commit in the database. I'd like to commit in a same transaction the update of my objectContext data and all ExecuteStoreQuery. Is it possible ?


Entity Framework: Using transactions and rollbacks... Possible?

0

精彩评论

暂无评论...
验证码 换一张
取 消