【发布时间】:2016-03-09 02:49:27
【问题描述】:
我无法理解的是是否可以对上下文进行更改并在提交之前在同一个事务中获取更改。
这就是我要找的:
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();
}
有人可以帮我理解并展示一个工作模式吗?
【问题讨论】:
标签: c# entity-framework-6 dbcontext transactionscope savechanges