撤销提交
var customer = ctx.Customers.Single(c => c.CustomerID == "AROUT");
customer.ContactName = "zhuye";
customer.Country = "Shanghai";
Response.Write(string.Format("Name:{0},Country:{1}<br/>", customer.ContactName, customer.Country));
customer = ctx.Customers.GetOriginalEntityState(customer);
Response.Write(string.Format("Name:{0},Country:{1}<br/>", customer.ContactName, customer.Country));
| 上面的代码执行效果如下:
Name:zhuye,Country:Shanghai Name:Thomas Hardy,Country:UK
| 批量操作
下面的代码会导致提交N次DELETE操作:
var query = from c in ctx.Customers select c;
ctx.Customers.RemoveAll(query);
ctx.SubmitChanges();
| 应该使用sql语句进行批操作:
string sql = String.Format("delete from {0}", ctx.Mapping.GetTable(typeof(Customer)).TableName);
ctx.ExecuteCommand(sql);
| 对于批量更新操作也是同样道理。
|
一步一步学Linq to sql(九):其它补充(三)
2010年05月17日 星期一 17:04
撤销提交
var customer = ctx.Customers.Single(c => c.CustomerID == "AROUT");
customer.ContactName = "zhuye";
customer.Country = "Shanghai";
Response.Write(string.Format("Name:{0},Country:{1}<br/>", customer.ContactName, customer.Country));
customer = ctx.Customers.GetOriginalEntityState(customer);
Response.Write(string.Format("Name:{0},Country:{1}<br/>", customer.ContactName, customer.Country));
| 上面的代码执行效果如下:
Name:zhuye,Country:Shanghai Name:Thomas Hardy,Country:UK
| 批量操作
下面的代码会导致提交N次DELETE操作:
var query = from c in ctx.Customers select c;
ctx.Customers.RemoveAll(query);
ctx.SubmitChanges();
| 应该使用sql语句进行批操作:
string sql = String.Format("delete from {0}", ctx.Mapping.GetTable(typeof(Customer)).TableName);
ctx.ExecuteCommand(sql);
| 对于批量更新操作也是同样道理。
|
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理