给定以下代码,方法DoDatabaseOperation()
和MethodAnotherContext()
将包含在事务中?请注意,context1
和context2
的类型相同,并且正在处理连接字符串。
using (EFContext context1 = new EFContext())
{
using (TransactionScope transScope = new TransactionScope())
{
DoDatabaseOperation(context1); // Call context1.functionImport to update records
while (....)
{
.................A lot of code............
context1.SaveChanges();
MethodAnotherContext();
}
transScope.complete();
}
}
public void MethodAnotherContext()
using (EFContext context2 = new EFContext())
{
......................
context2.SaveChanges();
}
}