2017-03-20 25 views
0

私はASP.NET Coreプロジェクトと既存のDB(MS SQLServer)を持っています。LINQ:リンクテーブルからデータを取得する(多対多の関係)

Component.cs

public partial class 
{ 
    public Component() 
    { 
     ComponentDocumentationLink = new HashSet<ComponentDocumentationLink>(); 

    } 

    public int IdConponent { get; set; } 
    public string ComponentName { get; set; } 
    public string ComponentTitle { get; set; } 
    public string ComponentDescription { get; set; } 
    public int IdComponentType { get; set; } 
    public int IdrecStatus { get; set; } 
    public DateTime CreateDate { get; set; } 
    public string CreateUser { get; set; } 
    public string ChangeUser { get; set; } 
    public DateTime? ChangeDate { get; set; } 


    public virtual ICollection<ComponentDocumentationLink> ComponentDocumentationLink { get; set; } 
    public virtual ComponentType IdComponentTypeNavigation { get; set; } 

} 

ComponentType.cs

public partial class ComponentType 
{ 
    public ComponentType() 
    { 
     Component = new HashSet<Component>(); 
    } 

    public int IdComponentType { get; set; } 
    public string ComponentTypeName { get; set; } 
    public int IdrecStatus { get; set; } 
    public DateTime CreateDate { get; set; } 
    public string CreateUser { get; set; } 
    public string ChangeUser { get; set; } 
    public DateTime? ChangeDate { get; set; } 

    public virtual ICollection<Component> Component { get; set; } 
} 

ComponentDocumentationLink.cs

public partial class ComponentDocumentationLink 
{ 
    public int IdComponentDocumentationLink { get; set; } 
    public int IdComponent { get; set; } 
    public int IdDocumentation { get; set; } 
    public int IdrecStatus { get; set; } 
    public DateTime CreateDate { get; set; } 
    public string CreateUser { get; set; } 
    public string ChangeUser { get; set; } 
    public DateTime? ChangeDate { get; set; } 

    public virtual Component IdComponentNavigation { get; set; } 

    public virtual Documentation IdDocumentationNavigation { get; set; } 


} 

とDocumentation.cs

:私はすでにDBから足場のモデルを持っています

a db model

問題は、私はコンポーネントおよびドキュメンテーション(多対多の関係)とコンポーネントとCOMPONENTTYPE(1対1の関係)との間には、テーブル間のリンクテーブルComponentDocumentationLinkを持っているということです。

コントローラの各コンポーネントにComponentTypeを取得しようとすると、var components = db.Component.Include(ct => ct.IdComponentTypeNavigation);に問題はありませんが、各コンポーネントのドキュメントからデータを取得するためのこのクエリの使用はありません。

答えて

0

解決策が見つかりました。ビュー内の

db.Something.Include(x => x.SomethingJunction).ThenInclude(x => x.JunctionedTable); 

そして:

@var a = item.SomethinJunction.Select(x => x.JunctionedTable); 
@a.Property; 
関連する問題