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?

2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.