zoukankan      html  css  js  c++  java
  • Linq to sql(九):其它补充(三)

    撤销提交

            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

    批量操作

           下面的代码会导致提交NDELETE操作:

            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);

           对于批量更新操作也是同样道理。

  • 相关阅读:
    面向对象(2)
    毕业季面试题(7)
    面向对象(class0420)
    ASP.NET入门(class0612)
    数据结构与算法(二叉树)
    算法总结(2)数据结构
    毕业季面试题(6)
    常规页生命周期(class0620)
    (三) 语句
    (二) 运算符
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749028.html
Copyright © 2011-2022 走看看