我开始使用MVC 3并使用MvcScaffolding来构建这些模型:
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; }
}
}
在搭建这些模型后,我可以创建会话和发言人,但在发言人视图中,我无法选择任何会话,而在会话视图中我无法选择任何发言人。
我如何添加这些并使它们成为mutliselect选项,这样我就可以为一个特定的会话选择10个发言者,例如?
提前致谢, Yosy
答案 0 :(得分:1)
在上下文类中需要这个:(这将创建一个关联表)
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Speaker>()
.HasMany(parent => parent.Session)
.WithMany();
}