I have a table in the database called Course_Predecessor and I'm trying to delete all the items from this table using EF and then adding new data to the table. I can't delete the data because I get the following error : "collection was modified enumeration operation may not execute"
this is the code I'm using (inside of a fucntion which recieves the context of the db as ctx)
List<Course_Predecessor> lst = new List<Course_Predecessor>();
fillTheList(ref lst , someData);
ctx.Course_Predecessor.RemoveRange(ctx.Course_Predecessor.ToList());
ctx.Course_Predecessor.AddRange(predecessors);
I get the error at the RemoveRange function.
would appreciate any help.
ctx.Course_Predecessor.RemoveRange(ctx.Course_Predecessor.ToList());without any surrounding code? This should work fine.