2011-05-13 104 views
0

我正在使用STE,並且希望爲對象及其子項啓用更改跟蹤。我現在需要做的就是這樣的事情。使用STE在子對象中啓用ChangeTracking

int id = 1; 

using(CustomerEntities context = new CustomerEntities()) 
{ 
    CustomerSection custSection = context.CustomerSections.Include("CustomerSections.Customers").SingleOrDefault(p => p.ID == id); 

custSection.StartTracking(); 

    foreach(Customer cust in custSection.Customers) 
    { 
     cust.StartTracking(); 
    { 

    return custSection; 

} 

我所尋找的是一個方法的子對象也沒有通過每一個有循環自動啓用更改跟蹤,並明確告訴它開始跟蹤變化。

在此先感謝您的任何見解。

回答

0

很可能您正在將自跟蹤實體與WCF結合使用。然後,不需要手動啓用更改跟蹤。這已經爲你完成了。生成STE的T4模板包含一個用[OnDeserialized]屬性裝飾的方法,一旦實體被反序列化(通常在到達客戶端後發生,並從WCF爲傳輸生成的xml中轉換回運行時類實例,該屬性開始跟蹤。看到確切的代碼示例:

[OnDeserialized] 
    public void OnDeserializedMethod(StreamingContext context) 
    { 
     IsDeserializing = false; 
     ChangeTracker.ChangeTrackingEnabled = true; 
    } 

搜索你的實體或T4模板,你很快就會發現這