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

  • SEARCH
  • Home
  • 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 6878751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:45:43+00:00 2026-05-27T04:45:43+00:00

Say have the following code: public void SaveOrUpdate(OrderContract orderContract) { foreach (var orderContract in

  • 0

Say have the following code:

public void SaveOrUpdate(OrderContract orderContract)
{
   foreach (var orderContract in orderContract.Tests)
   {

      Order order=dataAccess.FindOne<Order>(x=>x.OrderId==orderContract.OrderId) 
                  ?? new Order();

      // Where there are updates, put the stuff in the 
      // contract over what we already had.
      Mapper.Map(orderContract, order);

       // if it is new then add it in so it is inserted by EF.
      if (orderedTest.OrderedTestId <= 0)
          dataAccess.Add(orderedTest);

   }
   dataAccess.SaveChanges();
}

Does EF have anything that will care if someone updates an order after I retrieve it (in the FindOne call?

Or will it just happily overwrite any changes that have been done in between retrieving the data and my call to SaveChanges?

If it does not do that, then would a call ObjectContext.Connection.BeginTransaction be best to protect me? Or should I use new TransactionScope()?

And how can either of those know what rows I need to have in a transaction. (Just because I read a row does not mean that I want it locked. Or does it lock all tables in the model (yuck)).

Note: I am running with SQL Server 2008 R2 and EF 4.1

  • 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-27T04:45:44+00:00Added an answer on May 27, 2026 at 4:45 am

    By default, yes it will overwrite changed records. If you are worried about it for your app, read this:

    http://msdn.microsoft.com/en-us/library/bb738618.aspx

    By default, the Entity Framework implements an optimistic concurrency model. This means that locks are not held on data in the data source between when the data is queried and the data is updated. The Entity Framework saves object changes to the database without checking for concurrency. For entities that might experience a high degree of concurrency, we recommend that the entity define a property in the conceptual layer with an attribute of ConcurrencyMode=”fixed”…..(follow link to read more)

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

Sidebar

Related Questions

Let's say I have the following code: public void doSomething() { // begin transaction
Let's say I have the following code: public void Inject(Form subform) { this.tabControl1.TabPages[1].Controls.Add(subform); this.Refresh();
Lets say i have the following code private Func<T> _method; public void SetExecutableMethod<T>(Func<T> methodParam)
Lets say that I have the following code: public class Shelter<A extends Animal, B
Say suppose I have the following Java code. public class Example { public static
Let's say I have the following minimalistic HTML code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
Let's say we have the following piece of code: public class Event { }
Assume I have the following code: public static class Foo { public static void
Let's say you have the following code: public int getSpeedX() { speedLock.lock(); try {
Lets say I have the following code: public class Collection implements CollectionInterface{ ElementInterface[] elementArray

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.