I use EF almost one year ago. I just try to use TransactionScope deal with quite complex query like the following code.
using (var tran = new TransactionScope())
{
// Clear all data in some table
DataContext.SomeTables
.ForEach(x => DataContext.SomeTables.DeleteObject(x));
DataContext.SaveChanges();
// Import data from excel as DataSet object.
var ds = ImportDataFromExcel(file.FullName);
foreach (DataRow dr in ds.Tables[0].Rows)
{
DataContext.SomeTables.AddObject(new SomeTable
{
// fill object with data from current row.
});
}
DataContext.SaveChanges();
// Commit Transaction
tran.Complete();
}
After that, I got some error about DTM is not enabled or accessible. I know it cause by this service at database server is not start or blocked by firewall. But it is not my point.
I want to know why EF uses this service to create transaction while plain SQL script can use only some statement like "BEGIN TRAN", "SAVE TRAN" or "ROLLBACK TRAN" does that.
Is there any other way to avoid calling DTM service for my quite simple transaction statement?
PS. Current working database is so small and I think it should not be affect from different transaction technic.
Thanks,