2012-04-08 66 views
1
public static IQueryable<Institution> WithFunds(this IQueryable<Institution> query, IEnumerable<Fund> allowedFunds) 
    { 
     return query. 
    } 

我想要查询返回所有具有Institution.Funds'allowedFunds'列表中给出的任何基金的机构。请帮忙。使用IQueryable在另一个列表中搜索列表

我的课程结构是这样的。

public partial class Institution 
    { 
    public int Id { get; set; } 
    public virtual ICollection<Fund> Funds { get; set; } 
    } 

    public partial class Fund 
    { 
    public int Id { get; set; } 
    public virtual Institution Institution { get; set; } 
    } 

回答

1

你可以使用一个Contains查询:

Fund[] funds = allowedFunds.ToArray(); 
return query.Where(x => x.Funds.Any(f => funds.Contains(f))); 
相关问题