作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开始使用 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; }
}
}
最佳答案
你在你的上下文类中需要这个:(这将创建一个关联表)
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Speaker>()
.HasMany(parent => parent.Session)
.WithMany();
}
关于asp.net-mvc-3 - Mvc脚手架 : How to support many-to-many relationships between entities,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5930438/
我是一名优秀的程序员,十分优秀!