Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# linq Join (i think)

Posted on 2010-08-25
3
Medium Priority
?
329 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:MrKevorkian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:kris_per
ID: 33523097

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

0
 
LVL 16

Accepted Solution

by:
kris_per earned 2000 total points
ID: 33523139

Same using Where clause and to get it as IQueryable<Office>

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();

Open in new window

0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 33523224
great! thanks alot!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question