zoukankan      html  css  js  c++  java
  • LINQ to SQL语句(11)之Update

    LINQ to SQL语句(11)之Update

    更新(Update)

    说明:更新操作,先获取对象,进行修改操作之后,直接调 用SubmitChanges()方法即可提交。注意,这里是在同一个DataContext中,对于 不同的DataContex看下面的讲解。

    1.简单形式

    Customer cust =

      db.Customers.First(c => c.CustomerID == "ALFKI");

    cust.ContactTitle = "Vice President";

    db.SubmitChanges();

    语句描述:使用 SubmitChanges将对检索到的一个Customer对象做出的更新保持回数据库。

    2.多项更改

    var q = from p in db.Products

         where p.CategoryID == 1

        select p;

    foreach (var p in q)

    {

      p.UnitPrice += 1.00M;

    }

    db.SubmitChanges ();

    语句描述:使用SubmitChanges将对检索到的进行的更新保持回数 据库。

  • 相关阅读:
    读书笔记第四章
    读书笔记第三章
    读书笔记第二章
    读书笔记第一章
    第十章 读书笔记
    第九章 读书笔记
    第八章读书笔记
    第七章读书笔记
    第六章读书笔记
    第五章读书笔记
  • 原文地址:https://www.cnblogs.com/liubo/p/2381560.html
Copyright © 2011-2022 走看看