I was trying to delete a record - but I'm getting this error:
The instance of entity type 'Users' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values
I tried the following ways, but all failed with the same error.
var Users = context.Users.Where(x => x.Id.Equals(UsersId));
context.Users.RemoveRange(Users);
await context.SaveChangesAsync();
var Users = await context.Users.AsNoTracking().FirstOrDefaultAsync(x => x.Id.Equals(UsersId));
context.Users.Remove(Users);
await context.SaveChangesAsync();
var Users = new Users() {Id = UsersId};
context.Users.Attach(Users);
context.Users.Remove(Users);
await context.SaveChangesAsync();