Can Linq-to-SQL contribute or update as needed?

I have a distributed application that sends data through WCF to a server that will be stored in a database (SQL Server 2008).

Usually this data is new. So I just insert InsertAllOnSubmit ().

But sometimes, due to the peculiarities of communicating with handheld devices that launch the client side, I get an object that is already on the server.

Is there any way to say InsertOrUpdateAllOnSubmit? Or will I have to change my code to go through each object and check if it is in the database, and then do and insert or update as needed? I have quite a few types of objects, so it will be very tiring :(

+4
source share
2 answers

Modify the storage procedure in the database to handle Insert Duplicates.

+2
source

Usually, what I saw as a template for the script when trying to make any insertions or updates is a conflict, for example, existing objects, and then, as soon as you find a conflict, you request new data and apply your updates to it. This allows you to flexibly decide what change wins, or offer the user somehow to let them view new data and decide whether their data should win. It all depends on the context and business rules.

This mainly applies to updates, but perhaps if you think about why these conflicts arise for inserts, you can adapt your implementation to use the concurrency detection and resolution methods. http://msdn.microsoft.com/en-us/library/bb399373.aspx

+2
source

All Articles