i trying mapped delete procedure in ef (5.0, database first) use updated properties in entity parameters.
the mapped procedure takes 2 parameters:
deleterow: @id : int -> (key) id : int32 @modifiedby : char -> modifiedby : string in controller want change modifiedby value before delete procedure called.
subscription subscription = context.subscription.find(id); subscription.modifiedby = "test"; context.subscription.remove(subscription); context.changetracker.detectchanges(); context.savechanges(); however, when procedure called old value of modifiedby passed delete procedure.
i don't want update call database before deleting entity.
ended solving using none-tracked entities. got idea blog post: http://blogs.msdn.com/b/alexj/archive/2009/03/27/tip-9-deleting-an-object-without-retrieving-it.aspx
the asnotracking() method call added , after modifications entities attached context , removed.
subscription subscription = context.subscription.asnotracking() .include(i => i.relatedentity) .firstordefault(c => c.subscriptionid == id); subscription.modifiedby = "test-subcription"; subscription.relatedentity.tolist().foreach(f => f.modifiedby = "test_related"); context.subscription.attach(subscription); context.subscription.remove(subscription); context.savechanges(); this allows new modifiedby values sent mapped delete procedure. can set new values related entities, have mapped procedures , cascade deletion set.
Comments
Post a Comment