Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:27:10+00:00 2026-05-31T21:27:10+00:00

My question assumes simple inserts into a table with no relevant relations. // various

  • 0

My question assumes simple inserts into a table with no relevant relations.

// various unrelated operations w/context...
var one = new DbRecord();
var two = new DbRecord();
var thr = new DbRecord();
context.DbRecords.Add(one);
context.DbRecords.Add(two);
context.DbRecords.Add(thr);
// various unrelated operations w/context...
context.SaveChanges();

In this case, will my DbRecord entities always be inserted in the order I added them to the DbSet? They seem to be in my testing, but can I rely on this?

“various unrelated operations” refers to operations on different, not-related DbSets of the same context; inserts, deletes, and updated entities (POCOs, in my case)

I want them to be inserted in exact order so I can use the pk/identity field to sort by, yet I also need to take advantage of the implicit transaction that the context provides around my context.SaveChanges(). Although the other operations are not related as far as the database schema is concerned, the entries themselves are essentially log entries about the updates being performed, and their order is critical.

If the context does not guarantee inserting the records in the same order, I will have to add a datetime field to the records, and handle rolling back myself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:27:12+00:00Added an answer on May 31, 2026 at 9:27 pm

    This is not guaranteed according to the documentation. This means, that you cannot rely on this behavior. Basically, it comes down to the questions whether you are willing to take the risk that…

    • …your pager goes of in the middle of the night?
    • …you find, after running for a year, that 10% of these records are corrupt without any possibility to fix them retroactively?

    Answering these questions is up to you. Usually, the answer should be “no”.

    If your testing comes up ok, this does not mean that the “unrelated actions” your were talking about don’t cause any disturbance in rare situations. This is a silent bug that nobody will notice during testing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I ran into this tree question which LOOKED simple, but started driving me
Simple question, would love a solution if there is one! I assume there has
This question assumes there's a blessed central repository that members of a team clone
(For the purposes of this question, let us assume that one is intentionally not
Alright so a quick SQL question here(using sql-server-2008). I have a mapping table names
I know this is simple, but I don't really understand the homework-question: Assume the
pretty simple question I have here, but I couldn't find the answer: Assume I
Pretty simple question, but I can't seem to figure out how to do this,
Should be a simple question. I do not yet have 5.3 installed, so I
I have a fairly simple question that has me stymied. I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.