ASP.NET Core 3.1 and Entity Framework Core delete multiple records from database based on ID

Try this:

try
{
var assets =  await _context.Assets.Where(a => key.Contains(a.Id)).ToArrayAsync();

    if (assets == null)
    {
        return NotFound();
    }

   _context.Assets.RemoveRange(assets);
 var result=   await _context.SaveChangesAsync();
if(result==0) return BadRequest(" delete error");
}
catch(Exeption ex)
{

 return BadRequest (ex.Message);

}
return Ok();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top