开发者

Enable ChangeTracking In Child Objects Using STE

开发者 https://www.devze.com 2023-03-05 23:38 出处:网络
I\'m using STE and I want to enable change tracking for an object a开发者_C百科nd its children. What I currently have to do now is something like this.

I'm using STE and I want to enable change tracking for an object a开发者_C百科nd its children. What I currently have to do now is something like this.

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;

}

What I am looking for is a way to automatically enable change tracking for the child objects too, without having to loop through each one and explicitly tell it to start tracking changes.

Thanks in advance for any insight.


Most probably you are using Self Tracking entities in combination with WCF. Then it's not needed to enable the changetracking manually. this is already done for you. The T4 template that generates the STE's includes a method decorated with the [OnDeserialized] attribute which starts the tracking once entities are deserialized (which occurs normally after reaching the client and converted back into runtime class instances fromout the xml that WCF generated for the transport. See the exact code example:

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

Search your entities or the T4 template and you will find this soon.

0

精彩评论

暂无评论...
验证码 换一张
取 消