'Error In Update Record (The instance of entity type 'x' cannot be tracked)
I have this error when update record in RoleRepository.cs. what's the problem ?
The instance of entity type 'ApplicationRole' 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.
RoleController.cs
public async Task<IActionResult> Edit(RoleViewModel role)
{
if (await _roleService.ExsistNameAsync(role))
{
//show message duplicate name
}
await _roleService.UpdateAsync(role);
return Json(new { res = true, model = role });
}
RoleService.cs
public async Task<IdentityResult> UpdateAsync(RoleViewModel role)
{
var mapped = ObjectMapper.Mapper.Map<ApplicationRole>(role);
return await _roleRepository.UpdateAsync(mapped);
}
RoleRepository.cs
public async Task<IdentityResult> UpdateAsync(ApplicationRole role)
{
return await _roleManager.UpdateAsync(role);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
