LINQ IQueryable with List;输入参数
如果我输入一个字符串作为参数,以下函数效果很好,但我想为其提供一个字符串列表,即不是为其提供一个项目的名称,例如“AccountTracker”,我可以为它提供多个项目名称,即“AccountTracker”、“GameX”、“HR1”。如何转换 LINQ 查询来执行此操作?
存在以下关系 Employee(1--)EmployeeProjects(--1)Project
[WebGet]
public IQueryable<Employee> GetEmployeesByProjects(string project)
{
var employees = from ep in CurrentDataSource.EmployeeProjects
.Include("Project")
.Include("Employee")
where ep.Project.ProjectName == project
select ep.Employee;
return employees;
}
The following function works great if I enter one string as a parameter, but I would like to supply it a list of strings, i.e. instead of supplying it the name of one project, e.g. "AccountTracker", I can supply it multiple project names, i.e. "AccountTracker", "GameX", "HR1". How can I convert my LINQ query to do so?
There is the following relationship Employee(1--)EmployeeProjects(--1)Project
[WebGet]
public IQueryable<Employee> GetEmployeesByProjects(string project)
{
var employees = from ep in CurrentDataSource.EmployeeProjects
.Include("Project")
.Include("Employee")
where ep.Project.ProjectName == project
select ep.Employee;
return employees;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将项目作为字符串列表发送,您可以使用如下的 Contains 方法
,也可以将项目作为
"AccountTracker,GameX,HR1"
发送一个字符串send the projects as string list and you can use Contains method as below
or you can send one string with projects as
"AccountTracker,GameX,HR1"