Suppose I have the following class structure:
public class State
{
public int Id { get; set; }
public DateTime StatehoodDate { get; set; }
public IList<City> CityList { get; set; }
}
public class City
{
public int Id { get; set; }
public string CityName { get; set; }
}
Tied to the following tables in NHibernate:
CREATE TABLE tblState (
StateId int,
StatehoodDate datetime,
)
CREATE TABLE tblCity {
CityId int,
StateId int,
CityName varchar(1000)
}
*Note: Assume for this example, there are only 5-10 cities per state. This is an obfuscated example. *
I want to get all the states with a StatehoodDate after 1900. I also want a list of the cities in that state loaded automatically, so no lazy loading. How do I query this in NHibernate in a single query? (HQL, Criteria, etc. does not matter - I'll use whatever works.)
I'm hoping there's some way to get all the data back in one query and then do an equivalent of "GROUP BY" to get a list of only the states with a StatehoodDate after 1900. In my example, I will always display the cities every time this query is ran.
Lazy loading is obviously one option, but there is a performance hit, as there would be the initial query (on date) and then one query