2013-12-18 93 views
0

這裏是這個問題我的數據庫表: enter image description here實體框架選擇收藏

既然我已經選擇了WorkReleaseHeader,我現在想獲得有關WorkOrderDetails名單WorkReleaseHeader。似乎很容易,但我無法做到這一點。我feable嘗試:

List<WorkReleaseDetail> workReleaseDetails = 
((IEnumerable<WorkReleaseDetail>)wrkRlsHdr.WorkReleaseDetails).ToList(); 

List<WorkOrderDetail> workOrderDtlsForWorkRelease = 
    workReleaseDetails 
    .Select(wrkDtls => wrkDtls.WorkOrderHeader.WorkOrderDetails).ToList(); 

結果在錯誤的Select語句行:

Error 3 Cannot implicitly convert type 
'System.Collections.Generic.List<System.Collections.Generic.ICollection<WorkOrderDetail>>' 
to 'System.Collections.Generic.List<WorkOrderDetail>' 

回答

1

我認爲這應該工作:

List<WorkOrderDetail> workOrderDtlsForWorkRelease = 
    workReleaseDetails 
    .SelectMany(wrkDtls => wrkDtls.WorkOrderHeader.WorkOrderDetails).ToList(); 

在LINQ中的SelectMany可平的列表,以便在你的例子中,你將不會有一個列表的集合。

+0

謝謝@FloChanz這樣做! –