偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Linq DataLoadOptions描述

開(kāi)發(fā) 后端
這里介紹Linq to sql對(duì)Linq DataLoadOptions的使用是有限制的,它只支持1個(gè)1對(duì)多的關(guān)系。一個(gè)顧客可能有多個(gè)訂單,一個(gè)訂單可能有多個(gè)詳細(xì)訂單

Linq DataLoadOptions限制

Linq to sql對(duì)Linq DataLoadOptions的使用是有限制的,它只支持1個(gè)1對(duì)多的關(guān)系。一個(gè)顧客可能有多個(gè)訂單,一個(gè)訂單可能有多個(gè)詳細(xì)訂單:

  1. DataLoadOptions options = new DataLoadOptions();  
  2. options.LoadWith<Customer>(c => c.Orders);  
  3. options.LoadWith<Order>(o => o.Order_Details);  
  4. ctx.LoadOptions = options;  
  5. IEnumerable<Customer> customers = ctx.Customers.ToList<Customer>(); 

這樣的語(yǔ)句執(zhí)行后會(huì)導(dǎo)致下面的SQL執(zhí)行N次(參數(shù)不同):

  1. SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], 
    [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].
    [ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].
    [ShipPostalCode], [t0].[ShipCountry], [t1].[OrderID] AS [OrderID2], [t1].
    [ProductID], [t1].[UnitPrice], [t1].[Quantity], [t1].[Discount], (  
  2. SELECT COUNT(*)  
  3. FROM [dbo].[Order Details] AS [t2]  
  4. WHERE [t2].[OrderID] = [t0].[OrderID]  
  5. ) AS [count]  
  6. FROM [dbo].[Orders] AS [t0]  
  7. LEFT OUTER JOIN [dbo].[Order Details] AS [t1] ON [t1].[OrderID] = [t0].[OrderID]  
  8. WHERE [t0].[CustomerID] = @x1  
  9. ORDER BY [t0].[OrderID], [t1].[ProductID]  
  10. -- @x1: Input StringFixedLength (Size = 5Prec = 0Scale = 0) [ALFKI] 

而對(duì)于多對(duì)1的關(guān)系,Linq to sql對(duì)于Linq DataLoadOptions沒(méi)有限制:

  1. DataLoadOptions options = new DataLoadOptions();  
  2. options.LoadWith<Product>(c => c.Category);  
  3. options.LoadWith<Product>(c => c.Order_Details);  
  4. options.LoadWith<Order_Detail>(o => o.Order);  
  5. ctx.LoadOptions = options;  
  6. IEnumerable<Product> products = ctx.Products.ToList<Product>(); 

由于多個(gè)產(chǎn)品對(duì)應(yīng)1個(gè)分類(lèi),多個(gè)詳細(xì)訂單對(duì)應(yīng)1個(gè)訂單,只有產(chǎn)品和詳細(xì)訂單才是多對(duì)1的關(guān)系,所以也只會(huì)有1次SQL(不過(guò)這樣的操作還是少執(zhí)行為妙,消耗太大了)

  1. SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].
    [CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].
    [UnitsInStock], [t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].
    [Discontinued], [t3].[OrderID], [t3].[ProductID] AS [ProductID2], [t3].
    [UnitPrice] AS [UnitPrice2], [t3].[Quantity], [t3].[Discount], [t4].
    [OrderID] AS [OrderID2], [t4].[CustomerID], [t4].[EmployeeID], [t4].
    [OrderDate], [t4].[RequiredDate], [t4].[ShippedDate], [t4].[ShipVia], 
    [t4].[Freight], [t4].[ShipName], [t4].[ShipAddress], [t4].[ShipCity], 
    [t4].[ShipRegion], [t4].[ShipPostalCode], [t4].[ShipCountry], (  
  2. SELECT COUNT(*)  
  3. FROM [dbo].[Order Details] AS [t5]  
  4. INNER JOIN [dbo].[Orders] AS [t6] ON [t6].[OrderID] = [t5].[OrderID]  
  5. WHERE [t5].[ProductID] = [t0].[ProductID]  
  6. ) AS [count], [t2].[test], [t2].[CategoryID] AS [CategoryID2], [t2].
    [CategoryName], [t2].[Description], [t2].[Picture]  
  7. FROM [dbo].[Products] AS [t0]  
  8. LEFT OUTER JOIN (  
  9. SELECT 1 AS [test], [t1].[CategoryID], [t1].[CategoryName], [t1].
    [Description], [t1].[Picture]  
  10. FROM [dbo].[Categories] AS [t1]  
  11. ) AS [t2] ON [t2].[CategoryID] = [t0].[CategoryID]  
  12. LEFT OUTER JOIN ([dbo].[Order Details] AS [t3]  
  13. INNER JOIN [dbo].[Orders] AS [t4] ON [t4].[OrderID] = [t3].
    [OrderID]) ON [t3].[ProductID] = [t0].[ProductID]  
  14. ORDER BY [t0].[ProductID], [t2].[CategoryID], [t3].[OrderID] 

【編輯推薦】

  1. Linq結(jié)果集形狀概述
  2. Linq存儲(chǔ)過(guò)程返回詳解
  3. Linq調(diào)用LoadProducts方法
  4. Linq使用數(shù)據(jù)表簡(jiǎn)單描述
  5. Linq對(duì)象引用簡(jiǎn)單介紹
責(zé)任編輯:佚名 來(lái)源: IT168
相關(guān)推薦

2009-09-10 10:37:15

LINQ to SQL

2009-09-16 09:38:27

LINQ To SQL

2009-09-14 15:43:12

Linq Settin

2009-09-09 15:28:43

Linq to obj

2009-09-10 15:26:03

Linq City集合

2009-09-14 10:57:46

LINQ入門(mén)

2009-09-18 16:00:07

LINQ架構(gòu)

2009-09-15 16:26:36

Linq orderb

2009-09-08 09:24:50

LINQ查詢

2009-09-15 11:14:33

LINQ to SQL

2009-09-17 09:24:57

Linq實(shí)現(xiàn)分頁(yè)

2009-09-11 10:20:36

Linq擴(kuò)展方法

2009-09-14 16:33:55

LINQ To XML

2009-09-14 10:20:52

LINQ查詢語(yǔ)法

2009-09-09 11:14:04

Linq多個(gè)結(jié)果集

2009-09-10 09:09:40

Linq實(shí)體繼承

2009-09-16 10:58:13

Linq數(shù)據(jù)分組

2009-09-16 15:48:05

Linq修改XML文檔

2009-09-17 17:14:54

linq to sql

2009-09-18 13:53:09

LINQ工具集
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)