Main problem to solve:
How do I get "2 levels down" to get Owner.Pet[n].Toys and put it all in one object right away.
There are three entities in the system: Owner
, Pet
and Toy
.
I am trying to write a query (using LINQ's SQL-like notation) that will bring me single object of class Owner
with its inner properties filled = all pets assigned to that owner + each pet having all its toys.
This is what I have so far, it's not working as expected. SQL feelings tell me that I am missing GROUP JOIN somewhere...
var singleOwnerQuery =
from o in owners
join p in pets on o.FirstName = p.OwnerName
join t in toys on p.PetId = t.ToyUniqueId // each toy is unique - there are not "re-usable" toys
where o.Name == "..." && o.LastName == "..."
select new Owner
{
Pets = pets // this should already assign all the toys for each of the pets
};
Any help will be appreciated.
I skipped lot of other properties inside each of the classes to make it simpler