DataLoadOptions DataLoadOptions DataLoadOptions DataLoadOptions Class

定義

提供以進行相關資料的立即載入和篩選。Provides for immediate loading and filtering of related data.

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

範例

當您擷取Customers從 Northwind 範例資料庫中,您可以使用DataLoadOptions以指定Orders也是要擷取。When you retrieve Customers from the Northwind sample database, you can use DataLoadOptions to specify that Orders is also to be retrieved. 您甚至可以指定的哪些子集Orders擷取。You can even specify which subset of Orders to retrieve.

備註

一般General

當您查詢物件時,實際上只擷取了所要求的物件。When you query for an object, you actually retrieve only the object you requested. 相關物件不會自動擷取一次。The related objects are not automatically fetched at the same time. (如需詳細資訊,請參閱 < 跨關聯性查詢。)(For more information, see Querying Across Relationships.)

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.

規則Rules

請注意下列規則有關DataLoadOptions使用量:Note the following rules regarding DataLoadOptions usage:

循環處理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));

以下是一些一般的規則可幫助您了解在這些情況下可能發生的狀況。The following are some general rules that help you understand what occurs in these scenarios.

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.

  • 範例 4Where子句會針對所有執行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子句會套用到所有Bs,即使是在子查詢沒有BIn Example 5, the first Where clause is applied to all the Bs, even though there are subqueries on B. 第二個Where子句會套用到所有A即使是沒有 s 的子查詢上AThe second Where clause is applied to all the As even though there are subqueries on A.

建構函式

DataLoadOptions() DataLoadOptions() DataLoadOptions() DataLoadOptions()

初始化 DataLoadOptions 類別的新執行個體。Initializes a new instance of the DataLoadOptions class.

方法

AssociateWith(LambdaExpression) AssociateWith(LambdaExpression) AssociateWith(LambdaExpression) AssociateWith(LambdaExpression)

篩選針對特定關聯性所擷取的物件。Filters the objects retrieved for a particular relationship.

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

篩選針對特定關聯性所擷取的物件。Filters objects retrieved for a particular relationship.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAssociationCriteria(MemberInfo, LambdaExpression) GetAssociationCriteria(MemberInfo, LambdaExpression) GetAssociationCriteria(MemberInfo, LambdaExpression) GetAssociationCriteria(MemberInfo, LambdaExpression)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IsImmediate(MemberInfo) IsImmediate(MemberInfo) IsImmediate(MemberInfo) IsImmediate(MemberInfo)
LoadWith(LambdaExpression) LoadWith(LambdaExpression) LoadWith(LambdaExpression) LoadWith(LambdaExpression)

使用 lambda 運算式,擷取與主要目標相關之指定的資料。Retrieves specified data related to the main target by using a lambda expression.

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

指定當送出型別 T 物件的查詢時,要擷取的子物件。Specifies which sub-objects to retrieve when a query is submitted for an object of type T.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於