Update attempt in .NET Core throws exception

asp.net-core c# entity-framework-core

Question

I'm working on an application where.NET core identity isn't always required for login. However, if I attempt to update a record, the following exception is thrown.

The instance of entity type 'StApplications' cannot be tracked because another instance with the same key value for {'ApplicationId'} 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.ThrowIdentityConflict(InternalEntityEntry entry)

The table I want to update records in is StApplications.

Here is my source code:ApplicationRepository

public async  Task<StApplications> UpdateAsync(StApplications obj)
{
    var updatedApplication = _context.Update(obj);
     await _context.SaveChangesAsync();
    return updatedApplication.Entity;
}

Afterward, the code in myApplicationController the POST procedure

public async Task<IActionResult> Biodata(StApplications stApplications)
{
    var application = await _ApplicationRepository.GetByIdAsync(stApplications.ApplicationId) ;

    if (application == null)
    {
        return BadRequest(ModelState);
    }

    var updatedapplication = await _ApplicationRepository.UpdateAsync(stApplications);
    return RedirectToAction("Olevel", new { id = updatedapplication.ApplicationId});
}
1
0
9/30/2019 11:52:36 AM

Popular Answer

ZZZ_tmp
0
9/30/2019 12:45:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow