linq to object query

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?
}
 
M

Mr. Arnold

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).
 
K

kidders

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top