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<Country>()
.Property(e => e.Code)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<Country>()
.Property(e => e.PhoneCode)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<Country>()
.HasMany(e => e.Locations)
.WithRequired(e => e.Country)
.WillCascadeOnDelete(false);
}
Version 2:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Configure(modelBuilder.Entity<Country>());
}
Configure(EntityTypeConfiguration<Country> entity)
{
entity
.Property(e => e.Code)
.IsFixedLength()
.IsUnicode(false);
entity
.Property(e => e.PhoneCode)
.IsFixedLength()
.IsUnicode(false);
entity
.HasMany(e => e.Locations)
.WithRequired(e => e.Country)
.WillCascadeOnDelete(false);
}