2011-05-13 103 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模板,你很快就会发现这