How to Delete multiple records in Linq to Entity?

Viewed 46031

I have a tblA in sql:

id  int  (primary key)
fid  int 

data in tblA is:

1   1
2   1
3   2
4   2
5   3
6   3

i delete one record by following code:

DatabaseEntities obj = new DatabaseEntities();
int i = 2;
tblA t = obj.tblA.Where(x => x.fid == i).FirstOrDefault();
obj.DeleteObject(t);
obj.SaveChanges();

i delete multiple records by following code:

DatabaseEntities obj = new DatabaseEntities();
int i = 2;
while (obj.tblA.Where(x => x.fid == i).Count() != 0)
{
   tblA t = obj.tblA.Where(x => x.fid == i).FirstOrDefault();
   obj.DeleteObject(t);
   obj.SaveChanges();
}

Is there any solution for delete multiple records in linq to entity?

2 Answers
Related