Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这就是我现在所拥有的。
public ViewResult Index(string id) { var posts = db.Posts.Include(p => p.Blog.Id); return View(posts.ToList()); }
这是返回所有帖子,我如何做 linq 查询只给我 postwBlog.id == id
Blog.id == id
我相信您只需要使用 .Where() 过滤您的帖子。下面,我假设 Blog.Id 是一个字符串。如果没有,你将不得不适当地投射。
public ViewResult Index(string id) { var posts = db.Posts.Where(p => p.Blog.Id == id); return View(posts.ToList()); }