DataLoadOptions 類別

定義

提供即時載入與篩選相關資料的功能。

public ref class DataLoadOptions sealed
public sealed class DataLoadOptions
type DataLoadOptions = class
Public NotInheritable Class DataLoadOptions
繼承
DataLoadOptions

範例

當你從 Northwind 樣本資料庫檢索Customers時,可以用DataLoadOptions來指定也要檢索的。Orders 你甚至可以指定要檢索哪個子集 Orders

備註

DataLoadOptions 類別提供相關資料的即時載入與篩選功能。

當您查詢物件時,實際上只會擷取您所要求的物件。 相關物件不會同時自動擷取。 如需詳細資訊,請參閱 跨關聯性查詢

DataLoadOptions 類別提供兩種方法,以即時載入指定相關資料。 此 LoadWith 方法允許立即載入與主要目標相關的資料。 此 AssociateWith 方法允許篩選相關物件。

規則

請考慮以下關於 DataLoadOptions 使用規則:

手把週期

LoadWith 指令 AssociateWith 不應製造循環。 以下為此類圖的範例:

  • 範例 1:自我遞迴

    • dlo.LoadWith<Employee>(e => e.Reports);
  • 範例 2:後指點

    • dlo.LoadWith <Customer>(c => C.Orders);
    • dlo.LoadWith <Order>(o => o.Customer);
  • 範例三:較長的週期

    雖然這在正規化良好的模型中不應該發生,但這是可能的。

    • dlo.LoadWith <A>(a => a.Bs);
    • dlo.LoadWith <B>(b => b.Cs);
    • dlo.LoadWith <C>(c => c.As);
  • 範例 4:自我遞迴子查詢

    • dlo.AssociateWith<A>(a=>a.As.Where(a=>a.Id=33));
  • 範例 5:較長的遞迴子查詢

    • dlo.AssociateWith<A>(a=>a.Bs.Where(b=>b.Id==3));
    • dlo.AssociateWith<B>(b=>b.As.Where(a=>a.Id==3));

以下一般規則有助於你了解這些情境下會發生什麼:

  • LoadWith:每次呼叫 LoadWith 檢查圖中是否引入了環。 若有例外,如範例1、2和3,則會拋出例外。

  • AssociateWith執行時,引擎不會將現有的子查詢子句套用到表達式內的關係。

    • 在範例 4 中, Where 子句是對所有 A執行的,而不僅僅是被 SubQuery 表達式本身子過濾過的子(因為那會是遞迴的)。
    • 在範例 5 中,第一 Where 子句被套用到所有 Bs,儘管 上 B存在子查詢。 即使Where存在子查詢,A第二個子句仍套用於所有 As。

建構函式

名稱 Description
DataLoadOptions()

初始化 DataLoadOptions 類別的新執行個體。

方法

名稱 Description
AssociateWith(LambdaExpression)

過濾特定關係中擷取的物件。

AssociateWith<T>(Expression<Func<T,Object>>)

過濾特定關係中擷取的物件。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
LoadWith(LambdaExpression)

透過 lambda 表達式擷取與主要目標相關的指定資料。

LoadWith<T>(Expression<Func<T,Object>>)

指定在提交 T 型物件查詢時要檢索哪些子物件。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於