WCF 服务中的 Linq
本文关键字:Linq 服务 WCF | 更新日期: 2023-09-27 18:30:49
所以我从我的 GET 请求中返回一个集合,我注意到我想根据anyofthebelow
而不是单独返回一个组:
学生证
名
姓氏
我只知道如何在下面的代码中做到这一点,然后必须为每个方法创建不同的 GET 方法,有没有办法我可以调用GetStudentCollectionByGroup(string anything)
并从我的客户端返回上述细节列表,而无需为每个StudentID, FirstName, LastName
执行以下方法?
public List<Group> GetStudentCollectionByGroup(string studentID)
{
List<Group> groups = (from g in Groups
where
(from t in g.Groupsz where t.StudentID == studentID select t).Count() > 0
select g).ToList();
return groups;
}
public List<Group> GetStudentCollectionByGroup(string firstName)
{
List<Group> groups = (from g in Groups
where
(from t in g.Groupsz where t.FirstName == firstName select t).Count() > 0
select g).ToList();
return groups;
}
例如:
from t in g.Groupsz where t.StudentID == studentID select t
有OR方法吗?像这样:
where t.StudentID == anything OR t.FirstName == anything etc
P.S不太确定如何措辞标题(欢迎编辑)
当然
;您可以使用||
运算符:
where t.StudentID == studentID || t.FirstName == firstName