Can I get some guidance on how to make these functions async? Run table record delete, then, insert new data EF Core 2.2 - I am running into concurrency issues.
Routing_Tool_SO4is the main table that only gets updatesRouting_Tool_Servicesrecords are erased and new items are added every time.
RoutingToolController:
[HttpPut("updateSO4")]
public IActionResult UpdateSOJ4([FromBody] Routing_Tool_SO4 routing_Tool_SO4)
{
Routing_Tool_SO4 request = new Routing_Tool_SO4();
request.Id = routing_Tool_SO4.Id;
request.Routing_Tool_Services = routing_Tool_SO4.Routing_Tool_Services;
request.When = routing_Tool_SO4.When;
request.Where = routing_Tool_SO4.Where;
// needs to run first to erase secondary table
_repository.UpdateServiceSOJ4(request.Id);
// then update main table
_repository.UpdateSO4(request);
return Ok(request);
}
IRoutingToolRepo:
void UpdateServiceSO4(object routing_Tool_Service);
RoutingTool.cs:
// run first to erase records on secondary table
public void UpdateServiceSO4(object routing_Tool_Service)
{
var Id = new SqlParameter("Id", routing_Tool_Service);
var sql = _context.Routing_Tool_Service.FromSql("SELECT * FROM dbo.Routing_Tool_Service WHERE Routing_Tool_SO4Id = @Id", Id).ToList();
if (sql != null)
{
_context.Routing_Tool_Service.RemoveRange(sql);
_context.SaveChanges();
}
}
// run to update only the records on the main table
public void UpdateSO4(object routing_Tool_SO4)
{
_context.Update(routing_Tool_SO4).State = EntityState.Modified;
_context.SaveChanges();
}