我有两个 IQueryables:
public static IQueryable<Counterparty> SearchByCode(this IQueryable<Counterparty> queryable, string searchQuery)
{
return queryable.Where(x => x.Code.StartsWith(searchQuery.ToUpper()));
}
public static IQueryable<Counterparty> SearchByName(this IQueryable<Counterparty> queryable, string searchQuery)
{
return queryable.Where(x => x.Name.ToLower().Contains(searchQuery.ToLower()));
}
我想创建另一个 IQueryable 将这两个查询组合为 OR 例如
public static IQueryable<Counterparty> SearchByCodeOrName(this IQueryable<Counterparty> queryable, string searchQuery)
{
// return SearchByName(searchQuery) OR SearchByCode(searchQuery)
}
我宁愿避免重复代码,所以我想重用现有的可查询对象,而不是重写一个新的 lambda 表达式Where(x=> x.Code.StartsWith.... || x.Name.Contains.....)