2012-04-11 61 views
1

所以,我可是從我的GET請求返回集合,我注意到我想返回基於anyofthebelow而不是單獨一組:中的LINQ WCF服務

StudentID

姓氏

我只知道如何做到這一點在下面,而隨後不必爲每個不同的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 

是否有一個或方法?喜歡的東西:

where t.StudentID == anything OR t.FirstName == anything etc 

P.S不是很知道如何字標題爲這個(編輯歡迎)

+1

在您的名稱比較中觀察案例的靈敏度。 BOB!=鮑勃!=鮑勃。你或許應該使用的比較方法,它允許您控制像String.Compare的情況下 – user957902 2012-04-11 15:02:55

回答

3

當然;您可以使用||運營商:

where t.StudentID == studentID || t.FirstName == firstName