0
下一個實體的定義出發:LINQ的相關子查詢
Public Class Certificate{
public ID as int;
}
Public Class Authority{
ID int;
Certificates IEnumerable<Certificate>;
}
我的功能收到
2個集:IEnumerable<Certificate>
和IEnumerable<Authority>
。我需要選擇Authorities
,其中Certificates collection
在IEnumerable<Certificate>
輸入參數中至少有一個證書。
我最初的實現是枚舉IEnumerable<Certificate>
並使用Where(predicate)
選擇Authority
。
Public IEnumerable<Authority> SelectAuthorities(authList IEnumerable<Authority>, certList IEnumerable<Certificate>){
foreach (Certificate loadedCert in certList) {
yield return auth.Where(a => a.Certificados.Any(c1 => c1.IDCert == loadedCert.IDCert));
}
}
我認爲必須有使用更復雜的LINQ相關子查詢(我覺得它在「力」),以避免for循環的方式,但我不能找到它。
任何人都可以幫忙嗎?
運行完美。謝謝。這很簡單。我想我是在程序員的塊裏。 :) – jlvaquero 2013-05-13 08:48:49