Entity Framework configuration I tried to refactor my code with entity framework configuration, splitting in multiple private methods, one per entity, each responsible for configuring things related to that entity and only that entity. But I feel like Version 2 can still be improved.

What do you think?

Version 1:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity&lt;Country&gt;()
        .Property(e =&gt; e.Code)
        .IsFixedLength()
        .IsUnicode(false);

    modelBuilder.Entity&lt;Country&gt;()
        .Property(e =&gt; e.PhoneCode)
        .IsFixedLength()
        .IsUnicode(false);

    modelBuilder.Entity&lt;Country&gt;()
        .HasMany(e =&gt; e.Locations)
        .WithRequired(e =&gt; e.Country)
        .WillCascadeOnDelete(false);
}


Version 2:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    Configure(modelBuilder.Entity&lt;Country&gt;());
}

Configure(EntityTypeConfiguration&lt;Country&gt; entity)
{
    entity
        .Property(e =&gt; e.Code)
        .IsFixedLength()
        .IsUnicode(false);

    entity  
        .Property(e =&gt; e.PhoneCode)
        .IsFixedLength()
        .IsUnicode(false);

    entity
        .HasMany(e =&gt; e.Locations)
        .WithRequired(e =&gt; e.Country)
        .WillCascadeOnDelete(false);
}
My approach is to keep the XxxxxDbContext class as lightweight as possible:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    new ModelCreator().Execute(modelBuilder);
}




The ModelCreator class looks like this:

internal class ModelCreator
{
    public void Execute(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
        modelBuilder.Conventions.Remove&lt;OneToManyCascadeDeleteConvention&gt;();

        modelBuilder.Configurations.Add(new FirmConfiguration());
        // etc.
    }        
}




Then each table has its own EntityTypeConfiguration&lt;TEntityType&gt;:

internal class FirmConfiguration : EntityTypeConfiguration&lt;Firm&gt;
{
    public FirmConfiguration()
    {
        HasKey(x =&gt; new { x.Id });

        Property(t =&gt; t.Name).HasMaxLength(30).IsRequired();
        Property(t =&gt; t.Address).HasMaxLength(120).IsRequired();
        Property(t =&gt; t.PostalCode).HasMaxLength(4).IsRequired();
        Property(t =&gt; t.City).HasMaxLength(30).IsRequired();
        Property(t =&gt; t.Responsible).HasMaxLength(30).IsRequired();
        Property(t =&gt; t.Email).HasMaxLength(40).IsRequired();
        Property(t =&gt; t.Phone).HasMaxLength(14);
    }
}