linq to object query

Discussion in 'ASP .Net' started by kidders, Feb 11, 2010.

  1. kidders

    kidders Guest

    I have a class called Park which has a property which is a collection
    of another class ParkSeason. ParkSeason has two properties StartDate
    and EndDate.

    How would I go about writing a linq query that would return all parks
    where a date falls between the startdate and enddate of any of its
    parkseason collection.

    Something like:

    public List<Park> Search(DateTime StartDate)
    {

    List<Park> allPark = GetAllPark();
    var result =
    from myPark in allPark
    where myPark.SeasonCollection.Find(***)

    //not sure what to put from *** onwards, is there linq syntax, do i
    use a predicate/delegate?
    }
     
    kidders, Feb 11, 2010
    #1
    1. Advertising

  2. kidders

    Mr. Arnold Guest

    "kidders" <> wrote in message
    news:...
    >I have a class called Park which has a property which is a collection
    > of another class ParkSeason. ParkSeason has two properties StartDate
    > and EndDate.
    >
    > How would I go about writing a linq query that would return all parks
    > where a date falls between the startdate and enddate of any of its
    > parkseason collection.
    >
    > Something like:
    >
    > public List<Park> Search(DateTime StartDate)
    > {
    >
    > List<Park> allPark = GetAllPark();
    > var result =
    > from myPark in allPark
    > where myPark.SeasonCollection.Find(***)
    >
    > //not sure what to put from *** onwards, is there linq syntax, do i
    > use a predicate/delegate?
    > }


    var allparks = GetAllPark() ; // that's assuming that GetAllPark returns a
    List<T> and it has a List<T> within the List<T>
    // or collection with in a collection

    foreach(var park in allparks)
    {
    var theparks = (from park.sessioncollection.where(a => a.startdate >=
    StartDate && a.startdate <=StartDate).tolist();

    foreach(var thepark in theparks)
    {
    string date = thepark.startdate.tostring;
    }

    }

    If it's a collection, then the name should be plural (allparks) not
    (allpark) and some kind of plural name for the collection with in
    (allparks).

    To be honest, I don't know what you're trying to do here with a (.Find).
     
    Mr. Arnold, Feb 12, 2010
    #2
    1. Advertising

  3. kidders

    kidders Guest

    On 12 Feb, 00:21, "Mr. Arnold" <MR. > wrote:
    > "kidders" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > >I have a class called Park which has a property which is a collection
    > > of another class ParkSeason.  ParkSeason has two properties StartDate
    > > and EndDate.

    >
    > > How would I go about writing a linq query that would return all parks
    > > where a date falls between the startdate and enddate of any of its
    > > parkseason collection.

    >
    > > Something like:

    >
    > > public List<Park> Search(DateTime StartDate)
    > > {

    >
    > > List<Park> allPark = GetAllPark();
    > > var result =
    > > from myPark in allPark
    > > where myPark.SeasonCollection.Find(***)

    >
    > > //not sure what to put from *** onwards, is there linq syntax, do i
    > > use a predicate/delegate?
    > > }

    >
    > var allparks = GetAllPark() ; // that's assuming that GetAllPark returns a
    > List<T> and it has a List<T> within the List<T>
    > // or collection with in a collection
    >
    > foreach(var park in allparks)
    > {
    >    var theparks = (from park.sessioncollection.where(a => a.startdate >=
    > StartDate && a.startdate <=StartDate).tolist();
    >
    >    foreach(var thepark in theparks)
    >   {
    >       string date = thepark.startdate.tostring;
    >   }
    >
    > }
    >
    > If it's a collection,  then the name should be plural (allparks) not
    > (allpark) and some kind of plural name for the collection with in
    > (allparks).
    >
    > To be honest, I don't know what you're trying to do here with a (.Find).


    Thanks ill give that a whirl, as i stated above I hadnt actually
    proceeded to use the .find line, it was just a possibility for use
    with searching for what I wanted.

    As for the variable names, I prefer not to use a plural, just because
    they can contain one or more, but each to their own on that front.
     
    kidders, Feb 16, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ChrisN
    Replies:
    1
    Views:
    547
    Alexey Smirnov
    Aug 7, 2007
  2. shapper

    LINQ Query

    shapper, Oct 17, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    382
    sloan
    Oct 18, 2007
  3. Alex Sauceda

    SQL Query to Linq (Group By and Sum)

    Alex Sauceda, Feb 4, 2008, in forum: ASP .Net
    Replies:
    6
    Views:
    41,125
    Alex Sauceda
    Feb 4, 2008
  4. George

    Linq or not Linq

    George, Nov 4, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    370
    Mike Gleason jr Couturier
    Nov 5, 2008
  5. kidders

    linq to object query

    kidders, May 7, 2010, in forum: ASP .Net
    Replies:
    1
    Views:
    451
    Mr. Arnold
    May 7, 2010
Loading...

Share This Page