LINQ Query to retrieve multiple levels of relational data?

A Blog has many posts. Posts have many comments. How would I write a LINQ query to return entities down to the Blog.Posts.

Comments level? I believe, you could do the following to achieve this: var blog = (from be in _db.BlogSet. Include("Posts.

Comments") select b) In this case, for each blog, the posts and their comments will be fetched Marc.

A Blog has many posts. Posts have many comments. How would I write a LINQ query to return entities down to the Blog.Posts.

Comments level? I believe, you could do the following to achieve this: var blog = (from be in _db.BlogSet. Include("Posts.

Comments") select b); In this case, for each blog, the posts and their comments will be fetched. Marc.

That worked perfectly and keeps the code nice and clean – Craig M Aug 14 '09 at 6:26.

You can just use two from statements: var comments=from post in blog from comment in blog. Comments where comment. PostId==post.Id select comment.

This is good to know. It will come in handy when needing to include multiple nested entities. Thanks!

– Craig M Aug 14 '09 at 7:26.

I'm just getting up to speed with asp.net mvc and I'm wondering how one would go about getting relational data more than one level deep from the entity specified in the from clause. A Blog has many posts. Posts have many comments.

How would I write a LINQ query to return entities down to the Blog.Posts. The only (not so elegant) solution I came up with was to use a LINQ query to get Blog and Posts and then a foreach to get comments.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions