'Return function for list of id's
I have method that returns function for companySurveys
Here is it
private Func<IQueryable<Client>, IQueryable<CompanySurvey>> JoinCompanySurvey(int id,
IQueryable<CompanySurvey> companuSurveyQuery)
{
var function = (IQueryable<Client> companies) => from companySurvey in companuSurveyQuery
where companySurvey.Id == id
join company in companies
on companySurvey.CompanyId equals company.CompanyId
into res
from company in res
select companySurvey;
return function;
}
id parameter is companySurvey ID.
I need method that can work with list of id's.
So I can send here List and return function for many companySurveys
So same stuff as now, but for many.
How I need to rewrite this method?
Solution 1:[1]
How about this, change parameter int Id to IEnumerable<int> ids and in the func body change companySurvey.Id == id to ids.Contains(companySurvey.Id)
private Func<IQueryable<Client>, IQueryable<CompanySurvey>> JoinCompanySurvey(IEnumerable<int> ids,
IQueryable<CompanySurvey> companySurveyQuery)
{
var function = (IQueryable<Client> companies) => from companySurvey in companySurveyQuery
where ids.Contains(companySurvey.Id)
join company in companies
on companySurvey.CompanyId equals company.CompanyId
into res
from company in res
select companySurvey;
return function;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | marc_s |
