I have a list of some objects, which I populate from a database query result.
List<Competition> myList; // fetched from DB
If I need to access a property of one/several of the object in this list which requires to query the database again like this:
List<Person> compPersons = myList[0].Persons; // persons must be fetched in DB
then, is there a way to have but one db call which would fill Persons
property for every Competition
in myList
?
List<Person> comp1Persons = myList[0].Persons; // Causes one big DB fetch
List<Person> comp2Persons = myList[1].Persons; // no more fetch required
List<Person> comp3Persons = myList[2].Persons; // no more fetch required
If I have 1000 competitions in my list I don't want 1000 queries when I iterate over the list and access Persons property.
EDIT: I wouldn't mind using a IEnumerable instead of List, if it allows more possibilities.