1

My project is becoming quite large and my fluent api extensive.

Is there a way I can separate my fluent api concerns to multiple files and reference them in my OnModelCreating?

aaa
  • 184
  • 12
  • Nevermind, I found the answer: http://stackoverflow.com/questions/8319762/does-entity-framework-code-first-allow-for-fluent-mappings-in-separate-files – aaa Jun 02 '12 at 13:58
  • Possible duplicate of [Does Entity Framework Code First allow for fluent mappings in separate files?](https://stackoverflow.com/questions/8319762/does-entity-framework-code-first-allow-for-fluent-mappings-in-separate-files) – xdtTransform Jan 07 '19 at 10:01

1 Answers1

1

The link to the solution was not very specific, so here it is spelled out:

[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. The point to be mindful of is: When creating the constructor in the configuration, include the modelBuilder parameter.

  2. When adding the configuration in OnModelcreating, be sure to pass along the modelBuilder parameter.

aaa
  • 184
  • 12