In EF Core 2.0, we have the ability to derive from IEntityTypeConfiguration
for cleaner Fluent API mappings (source).
How can I extend this pattern to utili
There is another way to solve the problem, and that is to use Template Method Design Pattern. Like this:
public abstract class BaseEntityTypeConfiguration : IEntityTypeConfiguration
where TBase : BaseEntity
{
public void Configure(EntityTypeBuilder entityTypeBuilder)
{
//Base Configuration
ConfigureOtherProperties(builder);
}
public abstract void ConfigureOtherProperties(EntityTypeBuilder builder);
}
public class MaintainerConfiguration : BaseEntityTypeConfiguration
{
public override void ConfigureOtherProperties(EntityTypeBuilder entityTypeBuilder)
{
entityTypeBuilder.Property(b => b.CreatedDateUtc).HasDefaultValueSql("CURRENT_TIMESTAMP");
}
}
With this way you don't need to write any single line in child configuration.