I have these two entities:
public class TblUser
{
public long Userid { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string PasswordSalt { get; set; }
public string FullName { get; set; }
public virtual ICollection<TblNotify> TblNotifies { get; set; }
}
public partial class TblNotify
{
public Guid NotifyId { get; set; }
public string Message { get; set; }
public virtual TblUser ApprovalUser { get; set; }
}
The table tblNotify
has a foreign key Userid
.
DbContext
was initially built as singleton service.
I call an update method:
uow.GetRepository<tblNotify>().Update(item);
It almost always updates successfully, but rarely, I got this error:
The instance of entity type 'Tbluser' cannot be tracked because another instance with the same key value for {'Userid'} 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.
It's weird because I only update the tblNotify
table. How could I investigate this error further?
Any help will be appreciated.