實(shí)現(xiàn)設(shè)置ADO.NET數(shù)據(jù)屬性說(shuō)明
有很多值得學(xué)習(xí)的地方,這里我們主要介紹ADO.NET數(shù)據(jù),包括介紹ADO.NET數(shù)據(jù)等方面,在向大家詳細(xì)介紹ADO.NET數(shù)據(jù)之前,首先讓大家了解下ADO.NET數(shù)據(jù),然后全面介紹ADO.NET數(shù)據(jù),在這里拿出來(lái)和大家分享一下。。#t#
前面文章已經(jīng)介紹,介紹了Entity Data Model、Entity SQL、ObjectQuery、EntityCommand、LINQ to Entities等等及其代碼演示。Part 4主要演示如何通過(guò)相關(guān)技術(shù)或Debug工具,如SQL Server Profiler、ToTraceString 方法、eSqlBlast 工具、LINQPad工具等等,來(lái)查看生成的T-SQL腳本。Part 5 演示如何新增、更新和刪除數(shù)據(jù)實(shí)體,并相應(yīng)更新數(shù)據(jù)庫(kù)。本篇文章Part 6 演示如何處理并發(fā)更新。
設(shè)置并發(fā)模式
Entity Framework 實(shí)現(xiàn)了樂(lè)觀的并發(fā)模式(Optimistic Concurrency Model)。默認(rèn)情況下,ADO.NET數(shù)據(jù)在實(shí)體更新數(shù)據(jù)提交到數(shù)據(jù)庫(kù)時(shí),并不會(huì)檢查并發(fā)。對(duì)于高頻率的并發(fā)屬性,你需要設(shè)置屬性的并發(fā)模式為Fixed。
這些屬性將會(huì)加入到T-SQL腳本的WHERE子句部分,ADO.NET數(shù)據(jù)用來(lái)比較客戶端的值和數(shù)據(jù)庫(kù)端的值,示例代碼:
- public void UpdateProduct()
- {
- Product product = context.Product.FirstOrDefault(p => p.ProductID == 1004);
- if (product != null)
- {
- product.Color = "White";
- product.StandardCost = 200;
- product.ListPrice = 250;
- }
- context.SaveChanges();
- }