none
SaveChanges() and order of insert, update, delete commands RRS feed

  • Question

  • Is is possible to influence the order of insert, update, and delete commands SaveChanges() sends to the database?  Is it possible to even determine the rules EF uses to figure out what commands get sent first, second, third, etc.?  

    Example scenario ... three entities mapped to three different tables and the application code removes/adds/updates entities to and from the sets according to business logic.  How does EF determine what table gets updated first, second, and third?  How does EF determine which statements (insert, update, delete) come before or after other statements?

    Thank you.

     

    Friday, December 30, 2011 3:57 PM

All replies

  • Hi,

    For now I never seen an issue with the EF ordering (except perhaps one time someone posted about a cycling configuration ?). It's likely some kind of topological sort (http://en.wikipedia.org/wiki/Topological_sorting) i.e. it make sure that an operation is done after those it depends on...

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Friday, December 30, 2011 7:54 PM
  • Hi cats44,

    Based on my testing, I found the order for the three opertions is: Update--->Delete--->Insert.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chenModerator Monday, January 9, 2012 2:25 AM
    • Unmarked as answer by cats44 Monday, January 30, 2012 4:33 PM
    Monday, January 2, 2012 7:47 AM
    Moderator