Link to home
Start Free TrialLog in
Avatar of MrKevorkian
MrKevorkian

asked on

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.
Avatar of kris_per
kris_per


List<Office> offices = new List<Office>();

int startOfMyRange;
int endOfMyRange;

var query = from o in offices
                        where o.StaffForYears.Any(s => s.StaffCount <= startOfMyRange && s.StaffCount <= endOfMyRange)
                        select o;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kris_per
kris_per

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrKevorkian

ASKER

great! thanks alot!