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 6341185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:58:46+00:00 2026-05-24T19:58:46+00:00

I am a bit confused on the usage of DbContext in Entity Framework. Here’s

  • 0

I am a bit confused on the usage of DbContext in Entity Framework. Here’s the scenario I’m confused about.

  • I use a linq query from the dbcontext to get data. Something like:

    List<Transactions> transactions = DefaultContext.Transactions.ToList();
    
  • Then I update a column in one of the transactions returned in that query directly in the database.

  • Then I call again:

    List<Transactions> transactions = DefaultContext.Transactions.ToList();
    

When the list returns back this time, it doesn’t reflect the updates/changes I made when running the update statement, unless I loop through all my transactions and Reload them:

foreach (DbEntityEntry<Transactions> item in DefaultContext.ChangeTracker.Entries<Transactions>())
{
    DefaultContext.Entry<Transactions>(item.Entity).Reload();
}

Is this normal behavior? I assume that on my initial query, they are attached to the object context. Then when I query the second time, it doesn’t make a trip to the database, and just pulls out the entities from the object context, unless I clear/detach or individually reload all of the entities.

  • 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-24T19:58:47+00:00Added an answer on May 24, 2026 at 7:58 pm

    It is normal and in case of DbContext API fixed behaviour because from some very strange reason neither DbSet or DbQuery expose MergeOption property. In case of ObjectContext API you can set the behaviour by MergeOption exposed on ObjectSet and ObjectQuery. So if you want to refresh values from database (and lose your changes) you can do:

    ObjectContext objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
    ObjectSet<Transactions> set = objectContext.CreateObjectSet<Transactions>();
    set.MergeOption = MergeOption.OverwriteChanges;
    List<Transactions> transactions = set.ToList();
    

    If you just want to refresh transactions but you don’t want to lose your changes you can use MergeOption.PreserveChanges instead.

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

Sidebar

Related Questions

Bit confused here, I have an on-demand instance but do I get charged even
I'm a bit confused about the usage of Abstract classes in C#. In C++,
I am bit confused about the difference between the usage of std::remove algorithm. Specifically
I'm a bit confused about the use of Vim's menus. I have set wildmenu
I'm a bit confused about the exact use cases for jqueryui. What do you
I am a bit confused about the usage of cudaEvent_t . Currently, I am
I'm a bit confused about proper usage of svn in case of a single
I'm little bit confused about constants naming. kName NameKey NAME_KEY Definitely usage of these
I'm learning to use neo4j , but am a bit confused on its usage.
I am a bit confused about the usage of prototypes in Javascript. Let's take

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.