【问题标题】:Entity Framework: Multiple pages for OnModelCreating实体框架:OnModelCreating 的多个页面
【发布时间】:2012-06-02 13:54:52
【问题描述】:

我的项目越来越大,我的流利的 api 也很广泛。

有没有一种方法可以将我的 fluent api 关注点分离到多个文件并在我的 OnModelCreating 中引用它们?

【问题讨论】:

标签: entity-framework-4


【解决方案1】:

解决方案的链接不是很具体,所以在这里详细说明:

[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 参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多