Override default operations order in LINQ

Posted by Erick on Stack Overflow See other posts from Stack Overflow or by Erick
Published on 2010-05-05T14:43:52Z Indexed on 2010/05/05 14:48 UTC
Read the original article Hit count: 378

For one of our applications we do use LINQ to update a few reccords of the database.

For business reasons we do require that only one item of a list to be primary. When we designed we decided to fire all of queries at the database at once. The problems occurs when we add one row and update the primary element to be the second item.

See, the default behavior for order of operations with LINQ is to Insert, Update, Delete. If I Insert a first element I get a check constraint error with SQL Server.

The best in my opinion would be to override and make sure to Update before Insert, this way we make sure that check constraints are kept. Tho there is not a lot of documentation on the mather.

Any idea ?

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#