我在此看到这个问题,但似乎与我的情况不同。 我对此可能是错误的,但我们会看到这一点。
Right now I am creating a blog type website in MVC3 (C#) and I can currently create, edit, delete etc a blog just fine and everything works. I am using Code First EF, so I don t know how much that matters.
我有以下简称“博客”模式:
public class BlogPost
{
public int id { get; set; }
public string Title { get; set; }
public DateTime DateCreated { get; set; }
public ICollection<Topic> Topics { get; set; }
public string Content { get; set; }
public ICollection<Comment> Comments { get; set; }
}
(每个博客员额可以有多个专题)
public class Topic
{
public int id { get; set; }
public string Name { get; set; }
public int PostId { get; set; }
// navigation back to parent
public BlogPost Post { get; set; }
}
Then there is my DbContext inherited model with all of my models in it:
public class MyModel : DbContext
{
public DbSet<BlogPost> Posts { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<Topic> Topics { get; set; }
public DbSet<AdminComment> AdminComments { get; set; }
public DbSet<Bug> Bugs { get; set; }
}
目前,BlogController正在使用假装制造/编辑/提炼/尾料。
private MyModel db = new MyModel();
//
// GET: /Admin/Blog/
public ViewResult Index()
{
return View(db.Posts.ToList());
}
在另一个模式中,我能做些什么,在名单上也这样说,它将显示与这些员额有关的所有议题,并增加在你目前创建的职位上增加专题的内容?