'Use Multiple Linq queries in each other
Hi I use this code for deleting product object from DB
_context.Products.Remove(_context.Products.Find(id));
Is that true ? using Multiple Linq queries in each other ?
Solution 1:[1]
Although what you are doing is fine. But it is not the preferred way of removing something from the database. I would suggest you to find the record first and then check if it is found or not. If record exist in the DB, then delete the record.
var result = _context.Products.Find(id);
if(result != null){
_context.Products.Remove(result);
_context.SaveChanges();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | harrysrangal |
