【发布时间】:2013-05-31 16:39:21
【问题描述】:
在提供程序连接上启动事务时出错。有关详细信息,请参阅内部异常。 “不支持嵌套事务。” 内部异常
public bool Insert(myModel model)
{
entities.Database.Connection.Open();
using (DbTransaction trans = entities.Database.Connection.BeginTransaction())
{
try
{
table1 obj1 = new table1
{
AccountHolderName = model.AccountHolderName,
AccountNumber = model.AccountNumber,
Address = model.Address,
};
entities.table1.Add(obj1);
entities.SaveChanges();
long id = obj1.ID;
table2 obj = new table2
{
ID = model.ID == 1 ? id : model.ID,
Username = model.Email,
Password = model.Password,
};
entities.table2.Add(obj2);
entities.SaveChanges();
trans.Commit();
}
catch (Exception)
{
trans.Rollback();
}
finally
{
entities.Database.Connection.Close();
}
}
}
【问题讨论】:
标签: c# mysql entity-framework-4 entity