저는 엔티티 프레임 워크의 학습 곡선에 있습니다. 나는 msdn의 엔터티 프레임 워크에서 자습서를 따릅니다. 샘플에서 엔티티는 다음과 같이 정의됩니다.Hashset을 사용하여 객체를 초기화하는 방법
public class Department
{
public Department()
{
this.Courses = new HashSet<Course>();
}
// Primary key
public int DepartmentID { get; set; }
public string Name { get; set; }
public decimal Budget { get; set; }
public System.DateTime StartDate { get; set; }
public int? Administrator { get; set; }
// Navigation property
public virtual ICollection<Course> Courses { get; private set; }
}
public class Course
{
public Course()
{
this.Instructors = new HashSet<Instructor>();
}
// Primary key
public int CourseID { get; set; }
public string Title { get; set; }
public int Credits { get; set; }
// Foreign key
public int DepartmentID { get; set; }
// Navigation properties
public virtual Department Department { get; set; }
public virtual ICollection<Instructor> Instructors { get; private set; }
}
public class Instructor
{
public Instructor()
{
this.Courses = new List<Course>();
}
// Primary key
public int InstructorID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public System.DateTime HireDate { get; set; }
// Navigation properties
public virtual ICollection<Course> Courses { get; private set; }
}
일부 강의는 내 질문에만 집중되었습니다. 전체 샘플은 here입니다. 내 의심이 입니다 그들은 ICollection 속성을 생성하는 생성자에서 hashset 사용되는 이유는 무엇입니까?
HashSet의 성능은 '강사'기업의 constructor에에 목록으로 초기화 왜 HashSet의 다음
, 지역의 이러한 유형에 적합한 경우 설정 작업에 좋다?
간단히 2 가지 옵션을 표시 할 수 있습니다. 그러나 조언을주지 않으면 해시 세트를 사용하는 다른 일반적인 시나리오를 말해주십시오. 여기서 그들은 ICollection으로 리턴하며, 초기화를 위해서만 해시 셋을 사용했습니다.