Question : c# linq Join (i think)

HI,

i am using c# 3.5 and am trying to add to an existing linq query.  But am stuck on how to query a repeating property on a class.

Here are the details:

I working with the following entity structure

public class Office
{
      private int Id{get;set;}
      private List<StaffForYear> StaffForYears {get;set}      

}

public class StaffForYear
{
  public int Id{get;set;}
  public int Year{get;set;}  
  public StaffType StaffType{get;set;}
  public int StaffCount{get;set;}    

}

i am trying to write a linq query which says in psuedo code:

select * offices where Office.StaffForYear.StaffCount was <= startOfMyRange And
                  Office.StaffForYear.StaffCount was <= endOfMyRange      

Finally i want to do this using a "Where" clause on an existing IQueryable<Office> query.
As i am building up a dynamic query.

So something like  

   public IQueryable<Office> CreateStaffCountQuery(int startOfMyRange, int endOfMyRange, IQueryable<Office> query)

   {

     return query.Where(o => o.StaffForYears............);

   }



Thankyou very much.

Answer : c# linq Join (i think)


Same using Where clause and to get it as IQueryable<Office>
1:
2:
3:
4:
5:
6:
7:
List<Office> offices = new List<Office>();

int startOfMyRange;
int endOfMyRange;

IQueryable<Office> filteredOffices = offices.Where(o => o.StaffForYears.Any(s => s.StaffCount <= startOfMyRange && s.StaffCount <= endOfMyRange)).AsQueryable();
Random Solutions  
 
programming4us programming4us