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クエリを実行してpostwのみを取得するにはどうすればよいですか。Blog.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()); }