Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Error: CS8073: The result of the expression is always false since a value of type ValueTask is never equal to null

04.02.2023 (πŸ‘495)

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);

        }