Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 MVCSCapfolding:如何支持实体之间的多对多关系_Asp.net Mvc 3_Entity Framework 4_Ef Code First_Scaffolding - Fatal编程技术网

Asp.net mvc 3 MVCSCapfolding:如何支持实体之间的多对多关系

Asp.net mvc 3 MVCSCapfolding:如何支持实体之间的多对多关系,asp.net-mvc-3,entity-framework-4,ef-code-first,scaffolding,Asp.net Mvc 3,Entity Framework 4,Ef Code First,Scaffolding,我开始使用MVC 3,并使用MVCScapfolding构建这些模型: namespace Conference.Models { /* * Speaker can have many session * And session can have many speakers */ public class Speaker { public Guid Id { get; set; } [Required]

我开始使用MVC 3,并使用MVCScapfolding构建这些模型:

namespace Conference.Models
{
    /*
     * Speaker can have many session
     * And session can have many speakers
     */

    public class Speaker
    {
        public Guid Id { get; set; }
        [Required]
        public string Name { get; set; }
        public string Description { get; set; }

        public virtual ICollection<Session> Sessions { get; set; }
    }

    public class Session
    {
        public Guid Id { get; set; }

        [Required]
        public string Title { get; set; }
        [Required]
        public string Description { get; set; }
        [Required]
        public DateTime Hour { get; set; }

        public virtual ICollection<Speaker> Speakers { get; set; }
    }
}
名称空间会议.模型
{
/*
*演讲者可以有许多会话
*会议可以有许多发言者
*/
公共课演讲者
{
公共Guid Id{get;set;}
[必需]
公共字符串名称{get;set;}
公共字符串说明{get;set;}
公共虚拟ICollection会话{get;set;}
}
公开课
{
公共Guid Id{get;set;}
[必需]
公共字符串标题{get;set;}
[必需]
公共字符串说明{get;set;}
[必需]
公共日期时间小时{get;set;}
公共虚拟ICollection扬声器{get;set;}
}
}
搭建这些模型后,我可以创建会话和演讲者,但在“演讲者”视图中,我不能选择任何会话,在“会话”视图中,我不能选择任何演讲者

如何添加这些选项并使它们相互选择选项,以便我可以为一个特定会话选择10位发言者,例如

提前感谢,,
Yosy

您在上下文类中需要它:(这将创建一个关联表)

模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasMany(parent=>parent.Session)
.有许多();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
     modelBuilder.Entity<Speaker>()
                 .HasMany(parent => parent.Session)
                 .WithMany();
}