I am looking at the sql executed when I call SaveChanges on context, it does update , delete and insert sql stament in that order.. is there a way to change it to delete , update , insert ?
Asked
Active
Viewed 3,026 times
2 Answers
2
The only way that I can think of is to call your Delete()
first then SaveChanges()
then do the rest Insert()
and Update()
. Not saying that is the only way...
Looks like there is no way to change the order... - DbContext SaveChanges Order of Statement Execution

Community
- 1
- 1

bytebender
- 7,371
- 2
- 31
- 54
-
This answer is correct. To add a little, SaveChanges generates an order based on constraints between different tables/rows such that the save would succeed. Often using a different order will fail with constraint violations, at least on SQL Server and many other databases. – Arthur Vickers Mar 03 '12 at 00:47
-4
SaveChanges execute your changes in the same order that you added them to the datacontex. Make sure that you add them in the right order or at least an order that allows them to be executed.

Keren
- 81
- 2
- 10