I’m just going through the MVC tutorials on asp.net, (this one).
I just wanted to query something because I would have done it slightly differently and am now questioning why it is the way it is. (Or maybe I’m looking too much into it).
Regardless, they have these two methods in their repository class:
public Student GetStudentByID(int id)
{
return context.Students.Find(id);
}
public void DeleteStudent(int studentID)
{
Student student = context.Students.Find(studentID);
context.Students.Remove(student);
}
My initial instinct would have been to write DeleteStudent like this:
public void DeleteStudent(int studentID)
{
Student student = GetStudentById(studentID);
context.Students.Remove(student);
}
…but the fact they haven’t has made me wonder if there’s a reason as to why. Can someone help clarify please.
I don’t think there is a reason. Each way works. I prefer your code re-use over their example.