DataContext.DeferredLoadingEnabled 屬性


取得或設定值,指出是否要延遲載入一對多或一對一關聯性。Gets or sets a value that indicates whether to delay-load one-to-many or one-to-one relationships.

 property bool DeferredLoadingEnabled { bool get(); void set(bool value); };
public bool DeferredLoadingEnabled { get; set; }
member this.DeferredLoadingEnabled : bool with get, set
Public Property DeferredLoadingEnabled As Boolean


如果啟用延後載入則為 true,否則為 falsetrue if deferred loading is enabled; otherwise, false.


當程式碼存取其中一個關聯性時,如果關聯性為一對一,則會傳回 null,如果是一對多的,則會傳回空集合。When the code accesses one of these relationships, null is returned if the relationship is one-to-one, and an empty collection is returned if it is one-to-many. 您仍然可以藉由設定LoadOptions屬性來填滿關聯性。The relationships can still be filled by setting the LoadOptions property.

這個屬性的主要案例是讓您將物件模型的某個片段解壓縮,並將它傳送出去(例如,到 Web 服務)。The main scenario for this property is to enable you to extract a piece of the object model and send it out (for example, to a Web service).


如果在執行查詢之後將false這個屬性設定為,則會擲回例外狀況。If this property is set to false after a query has been executed, an exception is thrown. 如需詳細資訊,請參閱下面的「有效模式」一節。See the Valid Modes section below for more information.

有效模式Valid modes

延遲載入需要物件追蹤。Deferred loading requires object tracking. 只有下列三種模式有效:Only the following three modes are valid:

執行查詢之後,可能不會變更旗標。The flags may not be changed after a query has been executed. 執行第一個使用的查詢之後,如果發生任何變更DataContext ,就會擲回例外狀況。Any change after the execution of the first query that uses that DataContext throws an exception.