using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
using (var context = new DbContext())
{
//first I want to update an item in the context, not to the db
Item thisItem = context.Items.First();
thisItem.Name = "Update name";
context.SaveChanges(); //Save change to this context
//then I want to do a query on the updated item on the current context, not against the db
Item thisUpdatedItem = context.Items.Where(a=>a.Name == "Update name").First();
//do some more query
}
//First here I want it to commit all the changes in the current context to the db
scope.Complete();
}
Может ли кто-нибудь помочь мне понять и показать рабочий шаблон?
Я не могу понять, возможно ли внести изменения в контекст и получить изменения в той же транзакции до ее фиксации.
Это то, что я ищу:
[code]using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (var context = new DbContext()) { //first I want to update an item in the context, not to the db Item thisItem = context.Items.First(); thisItem.Name = "Update name"; context.SaveChanges(); //Save change to this context
//then I want to do a query on the updated item on the current context, not against the db Item thisUpdatedItem = context.Items.Where(a=>a.Name == "Update name").First();
//do some more query }
//First here I want it to commit all the changes in the current context to the db scope.Complete(); } [/code]
Может ли кто-нибудь помочь мне понять и показать рабочий шаблон?