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

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

  • 相关阅读:
    虚拟机简介
    关于JavaScript的那些话
    关于Python的那些话
    JavaScript教程大纲
    一个resin启动bug的解决
    Python教程大纲
    zinnia项目功能分析
    CDN公共资源
    Django Web项目部署参考
    Django Web项目代码规范参考
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749028.html
Copyright © 2011-2022 走看看