C# Linq建立一个帖子树

C# Linq建立一个帖子树,c#,asp.net,linq-to-entities,C#,Asp.net,Linq To Entities,我的示例代码只深入了两层,我希望它继续沿着树向下遍历,直到没有子级为止。有人知道我如何使用linq表达式来实现这一点吗 static List<Post> GetPosts(int postID) { var posts = from post in myEntities.Posts where post.PostID == postID || post.ParentPostID == postID select pos

我的示例代码只深入了两层,我希望它继续沿着树向下遍历,直到没有子级为止。有人知道我如何使用linq表达式来实现这一点吗

static List<Post> GetPosts(int postID) 
{
    var posts = from post in myEntities.Posts
           where post.PostID == postID || post.ParentPostID == postID
                select post).ToList();
} 
静态列表GetPosts(int postID)
{
var posts=myEntities.posts中的from post
其中post.PostID==PostID | | post.ParentPostID==PostID
选择post.ToList();
} 

您不能编写可以使用LINQ2实体转换为SQL的递归linq查询。我的建议是将POST放到内存中并遍历它们,或者使用