亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ADO.NET Entity FrameWork

發布時間:2020-07-28 02:21:04 來源:網絡 閱讀:367 作者:eryongyan 欄目:編程語言

 

缺點:Entity FrameWork 沒有提供獲取不同層上的對象的方式,無助于創建多層上的解決方案,可以結合WCF實現分層

核心概念:

邏輯層,SSDL store schema definition language描述數據庫表及其關系

概念層,CSDL conceptual schema definition L  描述 實體及關系

映射層 MSL  mapping Specification L  把CSDL實體類型定義映射到SSDL

查詢對象的三種方法

1. Entity SQL

Technorati 標簽: ADO.NET Entity FrameWork

using (var data = new Formula1Entities())

            {

                string country = "Brazil";

                ObjectQuery<Racer> racers = data.CreateQuery<Racer>(

                   "SELECT VALUE it FROM ([Formula1Entities].[Racers]) AS it WHERE it.Country = @Country",

                   new ObjectParameter("Country", country));

                foreach (var r in racers)

                {

                    Console.WriteLine("{0} {1}", r.Firstname, r.Lastname);

                }

            }

2.QueryBuilder

類似于LINQ,但Linq的參數是委托,而QueryBuilder的參數是字符串

可以用Find(),GroupBy(),OrderBy()等方法,

  using (var data = new Formula1Entities())

            {

                string country = "Brazil";

                ObjectQuery<Racer> racers = data.Racers.Where("it.Country = @Country", new ObjectParameter("Country", country));

                Console.WriteLine(racers.CommandText);

                Console.WriteLine(racers.ToTraceString());

            }

3. Linq to Entities

因為實體對象都繼承于ObjectQuery<T>,而該類實現了IQueryable接口

using (var data = new Formula1Entities())

            {

                var racers = from r in data.Racers

                             where r.Wins > 40

                             orderby r.Wins descending

                             select r;

                foreach (Racer r in racers)

                {

                    Console.WriteLine("{0} {1}", r.Firstname, r.Lastname);

                }

            }

增刪改查CRUD的實現

  using (var data = new Formula1Entities())

            {

                var jaime = new Racer

                {

                    Firstname = "Jaime",

                    Lastname = "Alguersuari",

                    Country = "Spain",

                    Starts = 0

                };

                data.Racers.AddObject(jaime);

           //添加

Racer niki1 = data.Racers.Where("it.Country='Austria' && it.Lastname='Berger'").First();

   data.Racers.DeleteObject( niki1 );

//刪除

  Racer niki2 = data.Racers.Where("it.Country='Austria'").OrderBy("it.Wins DESC").First();

niki2.Stars++;//修改

                int changes = 0;

                try

                {

                    changes += data.SaveChanges();

//提交到數據源

                }

   catch (OptimisticConcurrencyException ex)

                {

                    data.Refresh(RefreshMode.ClientWins, ex.StateEntries);

                    changes += data.SaveChanges();

                }

}

//懶惰加載

using (var data = new NorthwindEntities())

            {

                data.ContextOptions.LazyLoadingEnabled = false;

                int a = data.Customers.Count();

                foreach (Customer customer in data.Customers.Include("Orders"))

                {

                    Console.WriteLine("{0}", customer.CompanyName);

                    bool a2 = customer.Orders.IsLoaded;

              //   if (!customer.Orders.IsLoaded)

              //      {

              //          customer.Orders.Load();

                    }

                    foreach (Order order in customer.Orders)

                    {

                        Console.WriteLine("\t{0} {1:d}", order.OrderID, order.OrderDate);

                    }

                }

            }

data.ContextOptions.LazyLoadingEnabled = false;

LazyLoadingEnabled  懶惰加載,意思是在訪問對象時,會自動加載對象的相關屬性   

foreach (Customer customer in data.Customers)

LazyLoadingEnabled  默認為true,若設為false,則需要使用

Include("Orders")) 稱為預先加載

     customer.Orders.Load();(延遲加載

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

介休市| 务川| 女性| 临泽县| 赣州市| 铜陵市| 乌兰县| 白水县| 永昌县| 呼玛县| 克拉玛依市| 黄大仙区| 布尔津县| 双峰县| 盱眙县| 平泉县| 中江县| 靖宇县| 兴业县| 深泽县| 铅山县| 栾城县| 沾化县| 定兴县| 沙河市| 吴桥县| 辽中县| 兴化市| 兴和县| 尚志市| 宿松县| 马公市| 奉节县| 峨眉山市| 米林县| 裕民县| 恩施市| 望城县| 额尔古纳市| 庄河市| 余庆县|