PosDataContext db = new PosDataContext();
var tran = db.Connection.BeginTransaction();
db.Transaction=tran;
var temp=db.Product.Where(a => a.CategoryId == 1);
foreach (var x in temp)
{
Console.WriteLine("商品的SerialNumber为:{0}", x.SerialNumber);
x.SerialNumber = "N" + x.SerialNumber;
Console.WriteLine("商品的新SerialNUmber为:{0}", x.SerialNumber);
}
Console.WriteLine("总的改变有:{0}", db.GetChangeSet());
db.SubmitChanges();
tran.Commit();
可分布事务:
PosDataContext db = new PosDataContext();
using (var ts = new TransactionScope())
{
var tran = db.Connection.BeginTransaction();
var temp = db.Product.Where(a => a.CategoryId == 1);
foreach (var x in temp)
{
Console.WriteLine("商品的SerialNumber为:{0}", x.SerialNumber);
x.SerialNumber = "N" + x.SerialNumber;
Console.WriteLine("商品的新SerialNUmber为:{0}", x.SerialNumber);
}
Console.WriteLine("总的改变有:{0}", db.GetChangeSet());
db.SubmitChanges();
ts.Complete();
}