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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:44+00:00 2026-06-11T09:36:44+00:00

Is there an equivalent to this Rails brilliance for clearing a DB query cache

  • 0

Is there an equivalent to this Rails brilliance for clearing a DB query cache in Entity Framework (any version)? I keep having this problem and can’t seem to find an easy way to solve it:

All of the association methods are built around caching, which keeps the result of the most recent query available for further operations. The cache is even shared across methods….

But what if you want to reload the cache, because data might have been changed by some other part of the application? Just pass true to the association call:

customer.orders                 # retrieves orders from the database
customer.orders.size            # uses the cached copy of orders
customer.orders(true).empty?    # discards the cached copy of orders
                                # and goes back to the database
  • 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-06-11T09:36:45+00:00Added an answer on June 11, 2026 at 9:36 am

    It is possible but those methods are not available directly on entity. You must interact with context to achieve this.

    If you need to reload just single instance you can use:

    dbContext.Entry(order).Reload();
    

    If you need to reload multiple instances by single call you probably need to use ObjectContext API:

    var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
    objectContext.Refresh(RefreshMode.StoreWins, customer.Orders);
    

    Another approach is to run the query instead of using Refresh but that requires you to explicitly build a query to load correct orders:

    var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
    var objectSet = objectContext.CreateObjectSet<Order>();
    objectSet.MergeOption = MergeOption.OverwriteChanges;
    objectSet.Where(o => o.CustomerId == customer.Id).ToList();
    

    The main differences between query and Refresh will be performance (Refresh will probably use separate query for each order in collection) and new entities (refresh reloads only entities you specify whereas query will load new as well).

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

Sidebar

Related Questions

I wondering is there an equivalent of this feature from play framework http://www.playframework.org/documentation/2.0/JavaAsync Basicly
Is there any equivalent to this when a combo is data bound? I've been
Is there a jsp/jstl equivalent of this Rails error flash? <%- flash.each do |name,
Came across something like this today, and was wondering if there was an equivalent
In Ruby on Rails, how can I do the equivalent of this in a
Is there an equivalent of this pointer in VBA so that I can pass
Hey guys, I'm coming from a Zend Framework background, are there any auto form
I know there is no real equivalent in Rails but my question is mostly
Is there an equivalent of this in C# for static members? I like to
Is there an equivalent to Ruby On Rails' redirect_to :back in ASP.NET MVC? What

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.