I have what I think is a fairly basic flow in an asychronous web api controller. The code looks like the following:
public async Task<IHttpActionResult> Put([FromBody] ObjectType myObject)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
this.callbasicMethod();
myObject = await myRepository.UpdateDB(myObject);
await myRepository.DeleteSomeStuff(myObject.someProperty);
var table = Helper.CreateDataTable(myObject.anotherProperty);
await myRepository.InsertSomeStuff(table);
returnOk(myObject);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
The problem is that none of the database calls (importantly the update call) ever execute. If I put a break point in this method around the update call, everything works just fine. It is like some sort of race condition is happening or something. Please let me know if you have an idea on how to fix this issue or what I am doing wrong.
Also, please let me know if you need any clarification, I had to obviously obfuscate the code to protect the intellectual property of the company I work for. If it helps any, the methods that are being called are implemented asynchronously themselves calling into asynchronous dapper methods to communicate with the database.
I finally found a work around, but not a true answer to why. Basically the two database calls that were being called were to delete some data from the table and then after that had been done add some data to the same table. I wrote one stored procedure to handle this and then one method within my data layer of my application and now everything is working.