I have made some architectural MVC-mistake since I did not know of the
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
error.
My setup is as follows: I have a repository
for accessing the database which creates an instance of dbcontext
, I have controllers that instantiate managers
they need, the managers
all instantiate their own repository
. Here is the problem, when a controllers uses more than one manager
to collect data and then try to create an object that uses this data, the error above appears when adding the object to the dbcontext
.
I read about the UnitOfWork pattern, but it seems like a lot of work to restructure my code around that. Is there a quick fix to be able to update the database and avoid the error?
Thanks.