The instance of entity type SomeType cannot be tracked because another instance with the same key value for SomeField 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. Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap<TKey>.ThrowIdentityConflict(InternalEntityEntry entry)
public async Task<IActionResult> OnPostAsync(int? id) { var someClassVarFromTheRazorPage = SomeClass_IdentityFromTheRazorPage; //this comes as a Entity Model from the Razor Page and has some valuse SomeClass someClass = new SomeClass(); //this is second instance initialized someClass = await _context.SomeClass.FirstOrDefaultAsync(m => m.Id == id); //this is second instance with values from DB SomeClass_IdentityFromTheRazorPage.Time = someClass.Time; //assigning Time value from someClass with Db value to SomeClass_IdentityFromTheRazorPage with Page value _context.Attach(SomeClass_IdentityFromTheRazorPage); // Error await _context.SaveChangesAsync(); return RedirectToPage("/SomeClassIndex/SomeClassDetail", new { id = SomeClass_IdentityFromTheRazorPage.JobNo.ToString() }); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)