2013-12-03 82 views
0

我有3個實體,中間的一個連接外部的兩個。 我有一個RequestType1的值,我需要的是使用Linq的RequestField1的相應值。對於RequestType1值爲2Linq to entities導航屬性的複雜性

我的課是這樣

public partial class RequestField 
{ 
    public int RequestID { get; set; } 
    public int RequestField1 { get; set; } 
    public string FieldContents { get; set; } 

    public virtual FieldDefinition FieldDefinition { get; set; } 
    public virtual Request Request { get; set; } 
} 

public partial class FieldDefinition 
{ 
    public FieldDefinition() 
    { 
     this.RequestFields = new HashSet<RequestField>(); 
     this.RequestTypes = new HashSet<RequestType>(); 
    } 

    public int RequestField { get; set; } 
    public string FieldName { get; set; } 
    public string FieldReference { get; set; } 

    public virtual ICollection<RequestField> RequestFields { get; set; } 
    public virtual ICollection<RequestType> RequestTypes { get; set; } 
} 

public partial class RequestType 
{ 
    public RequestType() 
    { 
     this.Requests = new HashSet<Request>(); 
     this.FieldDefinitions = new HashSet<FieldDefinition>(); 
    } 

    public int RequestType1 { get; set; } 
    public string TypeDescription { get; set; } 

    public virtual ICollection<Request> Requests { get; set; } 
    public virtual ICollection<FieldDefinition> FieldDefinitions { get; set; } 
} 

回答

0

如果我在讀你的代碼的權利,這將是這樣的:

var requestFields = myRequestType.SelectMany(
            rt => rt.FieldDefinitions.SelectMany(
              fd => fd.RequestFields.Select(
               rf => rf.RequestField1))); 
+0

在數據庫中,我有一個表中有2個主鍵,我在其中創建了它成爲導航屬性的實體。 – Ernie

+0

你在說什麼餐桌? – IronMan84

+0

我有一個包含2個主鍵RequestType和RequestField的表。 – Ernie