Asp.net 如何从多对多结果返回VM?

Asp.net 如何从多对多结果返回VM?,asp.net,asp.net-mvc,asp.net-mvc-4,razor,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Razor,我想从GroupBook类返回一组书籍,它们具有相同的组id 这些表之间有这样的关系: public class GroupBook { [Key] public int Id { get; set; } [Required] public int Book_Id { get; set; } [Required] public string User_Id { get; set; } [Required] public int

我想从GroupBook类返回一组书籍,它们具有相同的组id

这些表之间有这样的关系:

public class GroupBook
{
    [Key]
    public int Id { get; set; }

    [Required]
    public int Book_Id { get; set; }

    [Required]
    public string User_Id { get; set; }

    [Required]
    public int Group_id { get; set; }

    public virtual AspNetUser AspNetUser { get; set; }

    public virtual Book Book { get; set; }

    public virtual Group Group { get; set; }

}

 public partial class Group
{
    public Group()
    {

        GroupBooks = new HashSet<GroupBook>();
    }
    [Key]
    public int Group_id { get; set; }

    [Required]

    public string Group_name { get; set; }

    public string Group_description { get; set; }

    public string UrlSlug { get; set; }

    public int state { get; set; }

    [Required]        
    public string User_Id { get; set; }

    public virtual AspNetUser AspNetUser { get; set; }

    public virtual ICollection<GroupBook> GroupBooks { get; set; }

}
如前一个示例所示,我只想返回一组具有相同组id的书籍,请如何将
DbSet GroupBooks
添加到
DbContext

然后做点什么:

var vm = new GroupVm();
vm.Book = db.GroupBooks.Where(g => g.Group_id == Group_id).Select(g => g.Book).ToList();
DbSet-groupbook
添加到
DbContext

然后做点什么:

var vm = new GroupVm();
vm.Book = db.GroupBooks.Where(g => g.Group_id == Group_id).Select(g => g.Book).ToList();
public ActionResult Index(int? Group_id)
    {            
        Vm=db.books.where(//What to add here to return set of books that == the group id I will send via method)
    }
var vm = new GroupVm();
vm.Book = db.GroupBooks.Where(g => g.Group_id == Group_id).Select(g => g.Book).ToList();