2017-04-22 1 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はそれを理解するでしょう。それ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; } 

} 

より:このようICollectionIEnumerableからナビゲーションプロパティの種類を変更します。

+0

ありがとうコーディングよし、私はそれをすぐに理解できなかったかもしれません。今働いている – Tom

関連する問題