- اگر قرار هست تعدادی read و write از و به بانک اطلاعاتی به صورت یک atomic operation عمل کنند، باید از تراکنشها به صورت صریح استفاده کنید:
using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { var database = new DatabaseContext(); // DBC: BEGIN TRANSACTION var userA = database.Users.Find(1); var userB = database.Users.Find(2); userA.Name = "Admin"; database.SaveChanges(); userB.Age = 28; database.SaveChanges(); // DBC: COMMIT TRANSACTION transaction.Complete(); }
«اصول پایگاه داده - تراکنش ها»
«آشنایی با TransactionScope»
«مفهوم READ_COMMITTED_SNAPSHOT در EF 6»
« بررسی Transactions و Locks در SQL Server»