在EF4和更高版本中使用TransactionScope时出错SQL Compact 4 [英] Error on using TransactionScope in EF4 & SQL Compact 4
本文介绍了在EF4和更高版本中使用TransactionScope时出错SQL Compact 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用(TransactionScope范围=新的TransactionScope())使用(var context = new dwfEntities()){var field =(从x在context.DynFields中,其中x.Id == id选择x).First();//删除默认值foreach(从上下文中的x输入var项.DynFieldDefaults,其中x.DynField_Id == id选择x){context.DeleteObject(item);}context.SaveChanges();//删除字段context.DeleteObject(field);context.SaveChanges();//犯罪scope.Complete();}
代码抛出无法在事务作用域中征用连接对象"
SQL CE 4是否支持TransactionScope?如果没有,是否有任何解决方法,以便我可以安全地删除对象?
解决方案
在SQL CE不支持事务范围的情况下,可以肯定地使用常规的事务处理方法connection.BeginTransaction然后transaction.Commit或Rollback ... >
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();
}
The code throws "The connection object can not be enlisted in transaction scope"
Does SQL CE 4 support TransactionScope ? if not, is there any workaround so I can safely delete objects ?
解决方案
in case SQL CE does not support transaction scope, you can surely use the normal transactional approach, connection.BeginTransaction then transaction.Commit or Rollback...
这篇关于在EF4和更高版本中使用TransactionScope时出错SQL Compact 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文