0

这就是我现在所拥有的。

    public ViewResult Index(string id)
    {
        var posts = db.Posts.Include(p => p.Blog.Id);
        return View(posts.ToList());
    }

这是返回所有帖子,我如何做 linq 查询只给我 postwBlog.id == id

4

1 回答 1

2

我相信您只需要使用 .Where() 过滤您的帖子。下面,我假设 Blog.Id 是一个字符串。如果没有,你将不得不适当地投射。

public ViewResult Index(string id)
{
    var posts = db.Posts.Where(p => p.Blog.Id == id);
    return View(posts.ToList());
}
于 2012-12-09T21:57:22.613 回答