I checked other questions and I am using the same DbContext for multiple actions so this is not the problem.
I have an MVC controller. Inside this controller I am doing the following:
var invites = await (from i in _db.Invitations
where i.User.Id == user.Id && i.Flat.Id == flat.Id
select i).ToListAsync();
_db.Invitations.RemoveRange(invites); //Error here
await _db.SaveChangesAsync();
Can someone explain to me why the error occurs?
Thanks a lot!
Edit: Thanks for your answers, i will try this. Currently I am instantiating my DbContext like this for each controller in my application.
private readonly ApplicationDbContext _db = new ApplicationDbContext();
Actually I don't like using a singleton for the DbContext. It should be possible to have another way. Maybe I will try to disable ChangeTracking or use usings for each and every action.
Thanks a lot. I will let you know tomorrow which solution I chose.
Hmm, I am receiving the error although I have
using(var db = new ApplicationDbContext){
...
}
around it ... any ideas?