Online Training for Asp.net MVC Web Designing Development, MS SQL, Digital Marketing

Delete data using Entity Framework Core

Here we learn how to delete data using entity framework core
How Delete works in EF Core
As I said in earlier tutorial that EF Core API can keep track of all the entities retrieved using the context, so when you delete or remove any data from context object and finally call the SaveChanges() method, all new changes made to context gets saved to database, thus data gets deleted from database also.

In entity framework core the delete method is replaced with remove();

Deleting single table using EF Core

public bool DeleteStudent(int stuid)
{
bool _isDeleted = false;
Student _s = null;
var context = new EFContext();
_s = context.tbStudent
.Where(s=>s.StuId==stuid)
.FirstOrDefault<Student>();

if (_s != null)
{
context.tbStudent.Remove(_s);
context.SaveChanges();
_isDeleted = true;
}

return _isDeleted;
}

Deleting from multiple tables using EF Core

Deleting multiple records using EF Core


Comment
Name Email Website
Subscribe
 
Delete example in EF Core

Group Training