[英]Linq: select parent based on sub collection
我的類型“下載”具有“ IEnumerable”的集合,並且正在嘗試返回下載中集合中符合條件的產品的集合。 到目前為止,這是我迄今為止的嘗試。 我認為問題是我需要選擇父級,因為我收到強制轉換錯誤subtypeA不會強制轉換為父級等。
public static IEnumerable<Download> GetDownloadsBasedOnProductId(int prodid)
{
var downloads =
(IEnumerable<Download>)
MyDataContext.Instance.Downloads.SelectMany(
x => x.bmdAType).Where(
a => a.Id == prodid);
return downloads;
}
關於查詢子項集合時如何返回正確類型的任何想法?
您是否正在尋找這樣的東西?
public static IEnumerable<Download> GetDownloadsBasedOnProductId(int prodid)
{
return MyDataContext.Instance
.Downloads
.Where(download => downloads.Any(a => a.Id == prodid));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.