views:

1081

answers:

2

Is there support in Linq to SQL for submitting changes to a single object? The SubmitChanges method sends all of the changes to the database, but what if I'm associating with an errorlog table and only want to save the records going into the errorlog without submitting all of the changes to my other tables?

Example:
Object Action (ID, Name, Type, Desc, Result)
Object ActionError (ActionID, ErrNum, ErrMsg)

There's an association between Action and ActionErrors by ID. When processing the Actions, something happens that I want to log an error for. I can add a new ActionError object to the collection of ActionErrors, but how I can send just those to the database without sending any changes to Action? Is using separate data contexts the only want to accomplish this in Linq to SQL?

+1  A: 

You could refresh the changed entity collections using the Refresh() method on the DataContext with RefreshMode.OverwriteCurrentValues, then update your ActionError and submit changes.

FWIW. I haven't done this, but looking at the docs this is what I would try.

tvanfosson
+2  A: 

Here is a good article about how to manage the lifetime of the Linq to SQL DataContext, might help you...

CMS
I should have know Rick Strahl would have covered this. Thanks!
Jeff Schumacher
From what I read, it looks like if you need to update one object at a time, you should steer clear of linq-to-sql. Was this your decision, Jeff, or am I missing some other solution to this?
mphair