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

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

  • 相关阅读:
    搭建armlinuxgcc交叉编译工具链环境(Android原生(JNI)开发环境搭建)
    linux vi命令详解
    Android手机在开发调试时logcat不显示输出信息的解决办法
    2012的总结和13的展望
    Gvim编码学习笔记
    vue自定义过滤器格式化时间为年、月、日、小时、分钟、刚刚 J
    学校网站群建设理念
    何为真正网站群?
    手机网站——移动互联网新趋势
    建站是浮云,We7很给力
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749028.html
Copyright © 2011-2022 走看看