c# - 在 EF4 和 SQL Compact 4 中使用 TransactionScope 时出错

标签 c# entity-framework sql-server-ce

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/

相关文章:

c# - 如果没有安装 Visual Studio,程序将无法启动?

c# - 无法使用 Gtk Builder 加载 glade 文件。 Gtk3#

c# - Asp.net MVC 异步速度很慢

excel - 当 SQL Select 包含长度大于 100 的 nvarchar 列时,VBA 出现多步错误

sql-server - 如何在 SQL Server Compact 中添加默认值?

c# - LinQ:C# 在使用一些过滤器复制时对数组进行排序

c# - 当数据库发生任何变化时,winforms 应用程序中的 Datagridview 会自动更新

c# - EF 代码优先 : separate creation of objects in db with TFT inheritance

sql - 通过 VB.NET 将 DateTime 插入 SQL Server CE 数据库

c# - 递归删除空文件夹,直到在目录树中找到非空目录