1

3 개의 테이블로 구성된 작은 응용 프로그램을 만들고 있습니다.EF 4.1에서 many to many 관계.

신청자 위치 신청자 위치.

이 마지막 하나는 다른 2 개의 테이블과 많은 관계가 될 것입니다.

그러나 코드 첫 번째 접근 방식을 사용하고 있지만 코드를 올바르게 작성했는지 여부가 확실하지 않습니다.

다른 2 개의 테이블에 ICollection 및 ICollection을 추가했습니다.

이 것이 맞나요? 필자는이 방법으로 관련 객체의 속성을 쉽게 탐색 할 수 있었지만, 결국 데이터베이스 초기 접근 방식으로 3 개의 테이블로 변환 될지 확실하지 않습니다.

예제 코드는 여기에 있습니다 :

public class Position 
    { 
     public int id { get; set; } 
     [StringLength(20, MinimumLength=3)] 
     public string name { get; set; } 
     public int yearsExperienceRequired { get; set; } 
     public virtual ICollection<ApplicantPosition> applicantPosition { get; set; } 
    } 

    public class Applicant 
    { 
     public int ApplicantId { get; set; } 
     [StringLength(20, MinimumLength = 3)] 
     public string name { get; set; } 
     public string telephone { get; set; } 
     public string skypeuser { get; set; } 
     public ApplicantImage photo { get; set; } 
     public virtual ICollection<ApplicantPosition> applicantPosition { get; set; } 

    } 

    public class ApplicantPosition 
    { 
     public virtual ICollection<Position> appliedPositions { get; set; } 
     public virtual ICollection<Applicant> applicants { get; set; } 
     public DateTime appliedDate { get; set; } 
     public int StatusValue { get; set; } 

     public Status Status 
     { 
      get { return (Status)StatusValue; } 
      set { StatusValue = (int)value; } 
     } 


    } 

답변

2

별도의 항목으로 조인 테이블을 모델링하는 경우 다음 해당 개체와 다른 두 개체 간의 일대 다 관계를 가지고있다. 또한 링크 엔터티의 속성으로 기본 키 열을 노출해야합니다.

public class Position 
{ 
    public int id { get; set; } 
    [StringLength(20, MinimumLength=3)] 
    public string name { get; set; } 
    public int yearsExperienceRequired { get; set; } 
    public virtual ICollection<ApplicantPosition> applicantPosition { get; set; } 
} 

public class Applicant 
{ 
    public int ApplicantId { get; set; } 
    [StringLength(20, MinimumLength = 3)] 
    public string name { get; set; } 
    public string telephone { get; set; } 
    public string skypeuser { get; set; } 
    public ApplicantImage photo { get; set; } 
    public virtual ICollection<ApplicantPosition> applicantPosition { get; set; } 

} 

public class ApplicantPosition 
{ 
    public int ApplicantId { get; set; } 

    public int PositionId { get; set; } 

    public virtual Position Position { get; set; } 

    public virtual Applicant Applicant { get; set; } 

    public DateTime appliedDate { get; set; } 
    public int StatusValue { get; set; } 

    public Status Status 
    { 
     get { return (Status)StatusValue; } 
     set { StatusValue = (int)value; } 
    } 
}