日期:2014-05-17 浏览次数:20425 次
DbConnection con = ((IObjectContextAdapter)ctx).ObjectContext.Connection;
con.Open();
using (var tran = con.BeginTransaction())
{
// 这里才是事务中的代码
tran.Commit();
}
con.Close();
using (CostManagementSystemEntities ent = new CostManagementSystemEntities())//在这个上下文里
{
tablename1 t1=new tablename1 ();//表1
tablename2 t2=new tablename2 ();//表2
ent.tablename1.AddObject(t1);
ent.tablename2.AddObject(t2);
ent.SaveChanges();
}