Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework core configurations

In EF 6 we could directly pass EntityTypeConfiguration to model builder to build maps and keep our configuration class separate from context without being too verbose in code.

Have they removed those maps in EF core. Is there a way to add configuration without doing it in model builder for every class?

like image 829
Jajan Avatar asked Mar 28 '17 13:03

Jajan


1 Answers

EntityFrameworkCore2.0 has a IEntityTypeConfiguration<TEntity> which can be used as:

class ApplicationUserMap : IEntityTypeConfiguration<ApplicationUser>
{
  public void Configure(EntityTypeBuilder<Customer> builder)
  {
    builder.ToTable("user", "identity");

    builder.Property(p => p.Id)
        .HasColumnName("id");
     ...
   }
}

...
// OnModelCreating
modelBuilder.ApplyConfiguration(new ApplicationUserMap());
like image 109
user2321864 Avatar answered Sep 25 '22 13:09

user2321864