I'm executing an update stored procedure from LINQ to SQL and I need to know the records affected after the update is called.
I'm using dbml designer to generate the LINQ code.
I'm executing an update stored procedure from LINQ to SQL and I need to know the records affected after the update is called.
I'm using dbml designer to generate the LINQ code.
Have you tried DataContext.GetChangeSet? For example, this returns the update count:
linqDbContenxt.GetChangeSet().Updates.Count
One way to do this would be to write out the rows updated into a table, and then read the table again with Linq-to-SQL:
UPDATE dbo.YourTable
SET columns = values
OUTPUT INSERTED.ID, INSERTED.column1, INSERTED.column2 -- etc. whatever you need
INTO dbo.OutputTable(.....)
Of course, you need to have created that dbo.OutputTable
before hand. After this operation has run, your output table will contain the values that have been updated. You can read that table like any regular table in Linq-to-SQL.
You could create another partial class for each object type in your dbml and hook to the various exposed methods such as OnCreated etc. You could make your own on update and keep a log of items modified, created or deleted as they happen to the actual objects
I've not tried any of the answers and I don't know which is the correct answer. I returned @@rowcount
as result set.