实体框架:OnModelCreating的多个页面

时间:2012-06-02 13:54:52

标签: entity-framework-4

我的项目变得非常庞大,我的流畅api广泛。

有没有办法可以将我的流畅api问题与多个文件分开并在我的OnModelCreating中引用它们?

1 个答案:

答案 0 :(得分:0)

解决方案的链接不是非常具体,所以在这里拼写出来:

[Context file]
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new Configurations.DataContext.EmployeeConfiguration(modelBuilder));
....
}

[Configuration file]
public class EmployeeConfiguration : EntityTypeConfiguration<Employee>
{
public EmployeeConfiguration(DbModelBuilder modelBuilder)
{ ...  }
....
}
  1. 需要注意的是:在配置中创建构造函数时,请包含modelBuilder参数。

  2. 在OnModelcreating中添加配置时,请务必传递modelBuilder参数。