## 定義

``public ref class DataLoadOptions sealed``
``public sealed class DataLoadOptions``
``type DataLoadOptions = class``
``Public NotInheritable Class DataLoadOptions``

## 備註

### 一般General

DataLoadOptions類別提供兩種方法可以達到指定的相關資料的立即載入。The DataLoadOptions class provides two methods to achieve immediate loading of specified related data. LoadWith方法可讓以立即載入與主要目標相關的資料。The LoadWith method allows for immediate loading of data related to the main target. AssociateWith方法是用來篩選相關的物件。The AssociateWith method allows for filtering related objects.

### 循環處理Cycle Handling

LoadWithAssociateWith指示詞不得建立循環。LoadWith and AssociateWith directives must not create cycles. 下列代表此類圖形的範例：The following represent examples of such graphs:

• 範例 1：自我遞迴Example 1: Self recursive

• `dlo.LoadWith<Employee>(e => e.Reports);`
• 範例 2：返回指標Example 2: Back-pointers

• `dlo.LoadWith <Customer>(c => C.Orders);`

• `dlo.LoadWith <Order>(o => o.Customer);`

• 範例 3：較長的循環Example 3: Longer cycles

雖然這不應該發生在已妥善正規化的模型，就可以了。Although this should not occur in a well-normalized model, it is possible.

• `dlo.LoadWith <A>(a => a.Bs);`

• `dlo.LoadWith <B>(b => b.Cs);`

• `dlo.LoadWith <C>(c => c.As);`

• 範例 4：自我遞迴的子查詢Example 4: Self recursive subQueries

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

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

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

LoadWith每次呼叫LoadWith會檢查是否已引進循環至圖形。LoadWith Each call to LoadWith checks whether cycles have been introduced into the graph. 如果有，如範例 1、 2 和 3，例外狀況會擲回。If there are, as in Examples 1, 2, and 3, an exception is thrown.

AssociateWith在執行階段引擎不會套用現有的子查詢子句運算式內的關聯性。AssociateWith The engine at run time does not apply the existing SubQuery clauses to the relationship inside the expression.

• 範例 4`Where`子句會針對所有執行`A`，而不只是子篩選由本身的子查詢運算式 （因為這樣才是遞迴）In Example 4, the `Where` clause is executed against all `A`, not just the ones sub-filtered by the SubQuery expression itself (because that would be recursive)

• 範例 5 中，第一個`Where`子句會套用到所有`B`s，即使是在子查詢沒有`B`In Example 5, the first `Where` clause is applied to all the `B`s, even though there are subqueries on `B`. 第二個`Where`子句會套用到所有`A`即使是沒有 s 的子查詢上`A`The second `Where` clause is applied to all the `A`s even though there are subqueries on `A`.