I have a type "Download" has a collection of "IEnumerable" and are trying to return a collection of downloads where a product in the collection matches condition. This below is my attempt thus far. I think the problem is I need to select the parent, as I receive cast errors subtypeA wont cast to parent etc.
public static IEnumerable&开发者_StackOverflow中文版lt;Download> GetDownloadsBasedOnProductId(int prodid)
{
var downloads =
(IEnumerable<Download>)
MyDataContext.Instance.Downloads.SelectMany(
x => x.bmdAType).Where(
a => a.Id == prodid);
return downloads;
}
Any ideas on how to return the correct type when querying a collection of subitems?
Are you looking for something like this?
public static IEnumerable<Download> GetDownloadsBasedOnProductId(int prodid)
{
return MyDataContext.Instance
.Downloads
.Where(download => downloads.Any(a => a.Id == prodid));
}
精彩评论