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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:22:27+00:00 2026-06-03T21:22:27+00:00

We have a IRepository pattern working quite well for us with our EF and

  • 0

We have a IRepository pattern working quite well for us with our EF and POCO first setup. However we are getting a strange problem with a “Collection was modified; enumeration operation may not execute”.

Basically we have a repository with an ObjectSet as follows:

protected IObjectSet<T> ObjectSet
{
  get
  {
    if (_objectSet == null)
    {
      _objectSet = this.Context.CreateObjectSet<T>();
    }

    return _objectSet;
  }
}

And a delete method on the IRepository class which is implemented as follows:

public void Delete(T entity)
{
  ObjectSet.DeleteObject(entity);
}

It’s all very straightforward and we’ve had no problems up until this point but whenever we try to delete an object of a collection we get this error. If I put a breakpoint on the delete method hover over ObjectSet and expand the results so it’s all loaded then the DeleteObject works fine but if all the items are not loaded form the ObjectSet it fails with the collection modified error.

I set up a testbed not using POCO or IRepository and it works fine so basically is there something really obbvious that I am missing. We are quite deep into using this pattern in multiple projects and people have been working around it rather than trying to fix it which isn’t an option I don’t think.

Many thanks for any help or insight.

EDIT:

This is very strange but when I remove certain entities from the model this error goes away but we have a huge model and I can’t track it down as I first removed everything but the specific tables in the delete. Has anyone ever come across this before, we are using inheritance tables (per type) but I can’t prove this is the problem.

SECOND EDIT:

OK I removed everything from the model except the table per type inheritance entites and the error occurs, when I remove all but one derived type and try to delete from that it works fine. So my question is has anyone else had this problem when using the table per type inheritance?

  • 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-03T21:22:28+00:00Added an answer on June 3, 2026 at 9:22 pm

    It’s a bug in Entity Framework. Fixed in 4.5 according to connect.

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

Sidebar

Related Questions

I'm working on a new project and I'm using the repository pattern, I have
The repository pattern seems to work well when working with an initial project with
I have a repository data access pattern like so: IRepository<T> { .. query members
I have a repository pattern setup using NHibernate. The base class looks like this:
I have implemented the repository pattern using the following generic interface. public interface IRepository<T>
I want to use EF Code First. I'm working with a repository pattern. And
I have the standard repository pattern with a service layer and I need to
I have a pretty standard Repository pattern going, where repositories are injected into my
I have my application designed with Repository pattern implemented and my code prepared for
I am using a simple repository pattern and have objects with a LazyList such

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.