using (TransactionScope scope = new TransactionScope())
using (var context = new dwfEntities())
{
var field = (from x in context.DynFields where x.Id == id select x).First();
//delete defaults
foreach (var item in from x in context.DynFieldDefaults where x.DynField_Id == id select x)
{
context.DeleteObject(item);
}
context.SaveChanges();
//delete field
context.DeleteObject(field);
context.SaveChanges();
//commit
scope.Complete();
}
代码抛出“无法在事务范围内登记连接对象”
SQL CE 4 是否支持 TransactionScope?如果没有,是否有任何解决方法以便我可以安全地删除对象?
最佳答案
如果 SQL CE 不支持事务范围,您当然可以使用正常的事务方法,connection.BeginTransaction 然后是 transaction.Commit 或 Rollback...
关于c# - 在 EF4 和 SQL Compact 4 中使用 TransactionScope 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5153573/