【发布时间】:2013-11-06 10:35:48
【问题描述】:
我的实体如下...
public class Project{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Survey> Surveys { get; set; }
}
public class Survey{
public int Id { get; set; }
public int ProjectId { get; set; }
public string Name { get; set; }
public virtual Project Project { get; set; }
}
public class Category{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Survey> Surveys { get; set; }
}
public class SurveyCategory{
public int Id { get; set; }
public int SurveyId{ get; set; }
public int CategoryId { get; set; }
public string Name { get; set; }
public virtual Survey Survey { get; set; }
public virtual Category Category { get; set; }
}
一个项目将有调查列表,一个调查将只有一个类别,一个类别可以有多个调查,调查类别是我存储调查 + 类别链接的表。
谁能告诉我什么是合适的 Fluent API 代码才能正确映射....到目前为止我有这个....
protected override void OnModelCreating(DbModelBuilder modelBuilder){
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<Project>().HasMany(project => project.Surveys);}
【问题讨论】:
标签: asp.net-mvc entity-framework one-to-many fluent-interface