文章出處

說明:更新操作,先獲取對象,進行修改操作之后,直接調用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將對檢索到的進行的更新保持回數據庫。


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()