I have several parent> child> grandchildren in my db schema. Usually I have a parent and I need information about my grandchildren. For example, I have a user who has a collection of social networks that have collections of friends. I find myself writing this code again and again.
var friends = new List<Friend>(); foreach (var socialNetwork in user.UserSocialNetworks) { foreach (var friend in socialNetwork.Friends) { friends.Add(friend); } }
Is there a more elegant way to do this with linq?
What I really would like to do is "user.Friends", but I would have to put the foreign key to the user in the friends table, and that doesn't smell right. Here's what it looks like:
User {Id,..} SocialNetwork {Id, UserId, ...} Friend {Id, SocialNetworkId, UserId, ... }
Thoughts?
DanielEli
source share