views:

109

answers:

0

I use LinqDataSource in my web pages and I want to handle Business rules in Changed event of properties and also OnValidate method of an entity. I can delete other entities in partial delete also, I can upload other entities in partial Insert and Update methos but I can't Insert entites in partial update or delete methods. Example : I have Server and ServerLog tables that each server has serveral serverlogs.one to many relation.when I want to update a server entity I want to add a new log entity to ServerLog table.Where I can do that? I don't want to do that in UI.I want to do that as business rule.I mean whereever I update a server entity a log is added to logservers.

 partial void UpdateServer(Server instance)
             {
             ServerLog lg = new ServerLog();
            lg.bState = true;
            lg.dState = DateTime.Now;
            lg.tDesc = "Server is updated.";
            lg.fkServer = instance.pk;

            ExecuteDynamicUpdate(instance);

            this.InsertServerLog(lg);
        }

the exception is:

The operation cannot be performed for the entity because it is not being change tracked. I have tried other ways such pass by session DataContext to OnValidate method and then do Insert serverlog but, it doesn't work. the exception is: context options cannot be modified after results have been returned from a query. Why? Is there some way for insert another entities in this methods? or at general not in UI but in datacontext?