G Gr
G Gr

Reputation: 6080

Linq in wcf service

So Im returning a collection from my GET request and I noticed I want to return a group based on anyofthebelow rather than individually:

StudentID

FirstName

LastName

I only know how to do it in the code below while then having to create different GET methods for each, is there a way I could call the GetStudentCollectionByGroup(string anything) and return the above list of specifics from my client without having to do the below method for each 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;
    }

For instance:

from t in g.Groupsz where t.StudentID == studentID select t

Is there an OR method? Something like:

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

p.s not very sure on how to word the title for this (edits welcome)

Upvotes: 1

Views: 100

Answers (1)

Cristian Lupascu
Cristian Lupascu

Reputation: 40526

Of course; you can use the || operator:

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

Upvotes: 3

Related Questions