Error: CS8073: The result of the
expression is always false since a value of type ValueTask<model?> is
never equal to null
Web api,
Controller
Falscher
Code, C#
[HttpDelete("{id}")]
public async
Task<ActionResult> Delete_Article(int id)
{
var dbArticle=
_dbContext.tbl_Articles.FindAsync(id);
if (dbArticle == null) return BadRequest("Article ID not
found");
//*remove the item
_dbContext.Remove(dbArticle);
await _dbContext.SaveChangesAsync();
return Ok(dbArticle);
}
|
Lösung:
Await in die Async Methode einbauen
[HttpDelete("{id}")]
public async
Task<ActionResult> Delete_Article(int id)
{
var dbArticle= await
_dbContext.tbl_Articles.FindAsync(id);
if (dbArticle == null) return BadRequest("Article ID not found");
//*remove the item
_dbContext.Remove(dbArticle);
await _dbContext.SaveChangesAsync();
return Ok(dbArticle);
}
|