How to delete multiple records with Entity Framework ASP.Net MVC 5?

asp.net-mvc-5 c# entity-framework

Question

I have Table like the following image:

enter image description here

how can I delete all records of table using Entity FrameWork based on ProjectId ?

1
27
11/28/2014 4:40:13 PM

Accepted Answer

This one liner will do it:

  db.ProRel.RemoveRange(db.ProRel.Where(c => c.ProjectId == Project_id));
78
11/28/2014 7:05:08 PM

Popular Answer

context.Projects.Where(p => p.ProjectId == projectId)
               .ToList().ForEach(p => context.Projects.Remove(p));
context.SaveChanges();

Taken from this very similar post (which should probably be marked as duplicate).



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow