linq to object query

  • Thread starter Thread starter kidders
  • Start date Start date
K

kidders

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 said:
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).
 
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.
 
Back
Top