2017-04-22 2 views
1

누군가 엔티티 프레임 워크가 다음 모델에 대한 조인 테이블을 작성하지 않는 이유를 알 수 있으면 고맙겠습니다. 그것은 유형 및 기능에 대한 테이블을 작성하지만 테이블을 결합하는 것은 아닙니다.엔티티 프레임 워크가 조인 테이블을 생성하지 않음

public class DeviceType 
    { 
     [Display(Name = "ID")] 
     public int DeviceTypeID { get; set; } 
     public string Name { get; set; } 
     public string Description { get; set; } 

     public IEnumerable<DeviceFeature> DeviceFeatures { get; set; } 
    } 

    public class DeviceFeature 
    { 
     [Display(Name = "ID")] 
     public int DeviceFeatureID { get; set; } 

     [Required]   
     public string Name { get; set; } 
     public string Description { get; set; } 

     public IEnumerable<DeviceType> DeviceTypes { get; set; } 

    } 

    public class DeviceFeatureView 
    { 
     public virtual IEnumerable<DeviceType> DeviceTypes { get; set; } 
     public virtual IEnumerable<DeviceFeature> DeviceFeatures { get; set; 
    } 
+0

두 엔티티 클래스 모두에서'IEnumerable '를'ICollection '로 변경하십시오. 'ICollection '은 EF 컬렉션 탐색 속성의 최소 요구 사항입니다. –

답변

1

다 대다 관계를 만들 때 브리지가 필요하지 않습니다. EF는 그것을 알아낼 것입니다. IEnumerable에서이 같은 ICollection에 탐색 속성의 유형을 변경합니다 : 그것은 here에 대한

public class DeviceType 
{ 
    public DeviceType() 
    { 
     this.DeviceFeatures = new HashSet<DeviceFeature>(); 
    } 
    [Display(Name = "ID")] 
    public int DeviceTypeID { get; set; } 
    public string Name { get; set; } 
    public string Description { get; set; } 

    public ICollection<DeviceFeature> DeviceFeatures { get; set; } 
} 

public class DeviceFeature 
{ 
    public DeviceFeature() 
    { 
     this.DeviceTypes = new HashSet<DeviceType>(); 
    } 
    [Display(Name = "ID")] 
    public int DeviceFeatureID { get; set; } 

    [Required]   
    public string Name { get; set; } 
    public string Description { get; set; } 

    public ICollection<DeviceType> DeviceTypes { get; set; } 

} 

더.

+0

감사합니다. 코딩 요시, 그렇게 빨리 이해할 수 없었습니다. 지금 일하고있다. – Tom

관련 문제