0

I have a student management. I can insert,update and delete students. But deleting is only possible with one ID and I want to delete a student by specifying two IDs. What do I need to add or change?

    public void DeleteStudentByIDs(int ID1, int ID2)
{
    var student = context.TableStudent.FirstOrDefault(x => x.id1 == ID1);
    context.TableStudent.Remove(student);
    context.SaveChanges();
}
ITDummie
  • 3
  • 1

1 Answers1

1

I think you should be able to do the following if you want to delete two students at a time

var students = context.TableStudent.Where(x => x.id1 == ID1 ||x.id1 == ID2);
context.TableStudent.RemoveRange(students);

Or keep your code, just changing the lambda to x.id1 == ID1 && x.id2 == ID2 in case you have a single student with two ids, where both has to match

JonasH
  • 28,608
  • 2
  • 10
  • 23