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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:19:03+00:00 2026-05-26T03:19:03+00:00

I have an MVC3 site with EF4.1 and repository/unit of work pattern and creating

  • 0

I have an MVC3 site with EF4.1 and repository/unit of work pattern and creating a new context per http request.

I want to implement custom object caching in Entity Framework 4.1. This means adding an object to the asp.net cache for faster retrieval by other similar http requests.

But the problem with EF is that these cached entities are attached to the context that was used to retrieve this entity in the first place and that got disposed after that http request was over.

Now when i want to update this cached object it gives me “An entity object cannot be referenceed by multiple instances of IEntityChangeTracker” Which makes complete sense.

What is the best practice to implement object caching in MVC3/EF4.1?

I am guessing you have to detach the entity from the old context while adding to the cache and attaching to the new context while retrieval. But i am surely not the first one to encounter this or try to implement this!

Are there any helpers or libraries out there? (please dont point me to http://code.msdn.microsoft.com/EFProviderWrappers/Release/ProjectReleases.aspx?ReleaseId=4747 as this removes ALL entries from cache on any update to a table, proving itself useless).

Thank you.

  • 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-26T03:19:04+00:00Added an answer on May 26, 2026 at 3:19 am

    “Best practice” would probably be to use a special DTO class to store on the session, and map to and from that class when you need to save or load information in the database.

    However, you should be able to achieve what you’re going for just by detaching and attaching the entity like you say. It shouldn’t be all that difficult if you consolidate your logic for adding and removing it from the session into a single class.

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

Sidebar

Related Questions

I have a .net mvc3 site and want to use the ActiveMq amq.js ajax
I have setup EF4.2 (Database First) with my MVC3 site. I have to entities
I'm new to MVC3 and have been working on a small site using EF
I have created a simple MVC3 web site and I want to limit access
I'm building my first MVC3 website and have connected my site to a mdf
I am working on a blog site, upgrading it to MVC3. I have this
I have an MVC3 program in which I want to query a database and
I have a MVC3 site in .Net 4.0 running on IIS6 with extensionless manner
I have an MVC3 site and I am writing code to register a user.
I have .net mvc3 web site. And i must to implement top menu. Each

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.