Last post Apr 19, 2021 06:19 PM by comicrage
Apr 19, 2021 06:19 PM|comicrage|LINK
UPDATE:" The Solution is
this.dbContext<ClassType>(Object).State = EntityState.Detached;
I am using entity framework core on .net core 3.1 which I am making two Update calls with the same dbContext Table instance. After the 2nd Update call, I am getting the following error
The instance of entity type 'MyEntitity' cannot be tracked because another instance with the same key value for MyEntityId is already tracked. When attaching existing entites, ensure thatt only one entity witha given key value is attached.
I read on the post, AsNoTracking can be added, but I don't see .AsNoTracking in the intellisense dropdown
I am calling two Update methods but the
The 1st update call this code
result = await this.debContext.SaveChangeAsync();
// so far so good, the records has been verified on the db to have the column value changed
On the 2nd call,
// after the 2nd Update call, the exception is called
this.dbContext.AsNoTracking but that is not available in the dropdown
I tried this.dbContext.ChangeTracker.AutoDetecteChangesEnabled = false
but that did not work.
I also looked for the .State property but could not find it to set it to EntityState.Detached.
Any help is appreciated. Thanks