How do I add all EntityTypeConfiguration<> from current assembly automatically?
public class Entities : DbContext
{
public Entities()
: base("Entities")
{
}
public virtual DbSet<User> Users { get; set; }
// ...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
foreach(var configuration in this.GetAllConfigurations())
{
modelBuilder.Configurations.Add(configuration);
}
}
private ... GetAllConfigurations()
{
// TODO: Get all configurations from current ASSEMBLY
}
}
It should be very easy as
DbModelBuilder
offers special method for that. Try add this withinOnModelCreating
method:Simpler Answer