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 s开发者_Python百科elect 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...
If the connection is opened outside of the transaction scope you need to explicitly call EnlistTransaction. You cannot implicitly use a connection with a transaction scope in SQL CE as described here
精彩评论