2011-11-29 3 views
1

MVC 자습서 asp.net, (this one)을 살펴 보겠습니다. 약간 다른 방식으로 질문했을 것이기 때문에 질문을하고 싶었지만 이제는 그것이 왜 그런지 질문합니다. (또는 어쩌면 나는 그것으로 너무 많이보고있다). 에 관계없이 , 그들의 저장소 클래스의 이러한 두 가지 방법이 있습니다MVC DRY - 메서드에서 메서드 호출

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); 
    } 

내 초기 본능이 같은 DeleteStudent를 작성했을 것이다 :

public void DeleteStudent(int studentID) 
    { 
     Student student = GetStudentById(studentID); 
     context.Students.Remove(student); 
    } 
...하지만 사실 그들은 천국 ' 왜 그런지 이유가 있는지 궁금하게 만들었습니다. 누군가 명확히 도와 줄 수 있습니까?

답변

3

나는 이유가 있다고 생각하지 않습니다. 각 방법이 효과가 있습니다. 나는 당신의 코드 재사용을 선호한다.

+0

문제를 해결해 주셔서 감사합니다. – Oppdal

관련 문제