I'm just speeding up with asp.net mvc, and I'm wondering how one could get relational data to a depth of more than one level from the object specified in the from clause. As an example, you can use the following domain model:
There are a lot of blog posts. Posts have many comments.
How do I write a LINQ query to return entities to the Blog.Posts.Comments level?
The only (not very elegant) solution I came across was to use the LINQ query to get the blog and posts, and then to get comments.
var blog = (from b in _db.BlogSet.Include("Posts") select b); foreach (Post p in blog.Posts) { var comments = (from c in _db.CommentSet where c.PostId = p.Id select c); p.Comments = comments; }
source share