开发者

insert in dymanic update - linq to sql

I'm developing a dynamic data app, in which I'm trying perform insert RequestRevision during update of request (logging change of request, somthing like that)

public partial class ProjectDataContext  
    {
        partial void UpdateRequest(Request instance)
        {                
            RequestRevision rv = new RequestRevision(Requests.GetOriginalEntityState(instance));                 
            this.ExecuteDynamicInsert(rv);                
开发者_JAVA技巧            this.ExecuteDynamicUpdate(instance);
        }
    }

this code error "The operation cannot be performed for the entity because it is not being change tracked."

when I added code for change tracking

public partial class ProjectStatusDataContext  
    {
        partial void UpdateRequest(Request instance)
        {
            bool tracking = ObjectTrackingEnabled;
            ObjectTrackingEnabled = true;
            RequestRevision rv = new RequestRevision(Requests.GetOriginalEntityState(instance));
            //instance.RequestRevisions.Add(rv); --not working 
            this.ExecuteDynamicInsert(rv);
            //this.RequestRevisions.InsertOnSubmit(rv); -- not working
            ObjectTrackingEnabled = tracking;
            this.ExecuteDynamicUpdate(instance);
        }
    }

Now I'm getting error "Data context options cannot be modified after results have been returned from a query."


I achieve this using sql triggers. Which fire when an update id performed on the request table.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜