Lets look at some very simple example, have 3 tables:
- dbo.Person(PersonId, Name, Surname)
- dbo.Pet(PetId, Name, Breed)
- dbo.PersonPet(PersonPetId, PersonId, PetId)
Need to select all persons with theirs pets if person has any.... for ex. in final application it should look smth like:
whats the most efficient way:
- Select all persons and then in data access layer fill each person pets list with separate select?
- Use join in sql level and then in data access layer filter all persons duplicates, by adding only one to result list and from other just filling pet list?
- any other ideas?