We have been using data luxuriously so far without keeping usage in mind. One fine example is the delete
operation, which we can see in all the CRUD operations. If we take a look at the Person
delete
operation, we can see that the entire Person
entity was returned from the context and it was used for the deletion. The following code retrieves the Person
entity and uses the entity for delete operation:
public async Task<IActionResult> DeleteConfirmed(int id) { var person = await _context.People.SingleOrDefaultAsync(m => m.Id == id); _context.People.Remove(person); await _context.SaveChangesAsync(); return RedirectToAction("Index"); }
The pitfall for the preceding approach was, first a database call was made to retrieve the entire Person
object, which is an overhead. After that, the required delete
operation was performed using the Id
of the person, which was available before the Person
retrieval. The following screenshot...