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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:32:26+00:00 2026-05-23T05:32:26+00:00

This seems a lot harder than it should be. I’m writing an event registration

  • 0

This seems a lot harder than it should be.

I’m writing an event registration site using MVC3, SQL Compact Edition, and Entity Frameworks Code First, and making use of Steven Sanderson’s Mvc Scaffolding NuGet package.

Since the list of events isn’t likely to change much, I’m caching it into a global list in the Application_Start method:

        var repo = new RaceEventRepository();
            EventRaces =
                repo.All.Where(r => r.RaceName.Contains(eventName)).Select(r => r).ToList();

where RaceEventRepository is a repository class constructed by MvcScaffolding, and does a

EventContext context = new EventContext();

which is then used through out the repository, and (I assume) disposed of when the Repository is disposed of.
and EventRaces is a globally available List.

My problem is that when I then create a registrant record with a foreign key back to the RaceEvent that is stored in EventRaces , I’m getting an error “An entity object cannot be referenced by multiple instances of IEntityChangeTracker.”

According to several blog posts and SO answers, I need to Detach the cached entities from the context as in Listing 1 of this post.

My problem is that, using ObjectBrowser, I can’t find anything with a Detach method. context in the Repository doesn’t have one. The individual DbSets in the context don’t have one (although they have an Attach() method). System.Data.Object.ObjectSet has one, but I can’t find a mapping between a DbSet and an ObjectSet.

Clearly, I’m missing something. Can somebody point me in the right direction?

  • 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-23T05:32:27+00:00Added an answer on May 23, 2026 at 5:32 am

    You can either use the AsNoTracking extension method to query your list without attaching the objects to the context …

    var repo = new RaceEventRepository();
    EventRaces = repo.All.AsNoTracking()
        .Where(r => r.RaceName.Contains(eventName))
        .ToList();
    

    … or you can detach single entities from the context by settings their state to Detached:

    context.Entry(raceEvent).State = EntityState.Detached;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems this should be easy but I'm having a lot of difficulty using
Ok, this seems to be a typical error as of discussing a lot in
This question seems to have been asked a lot, but I haven't seen an
I have read a lot about this issue but mine still seems to be
This is a lot more complicated than it might seem at first. What I
After reading a lot on this subject and discussing on IRC, the response seems
I'm not sure if this should go here, or on superuser (as it seems
This may seem a trivial question, but it's one that's bothered me a lot
I seem to run into this situation quite a lot and have yet to
I know that there are lot's of questons on this, but all seem 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.