Use IEntityTypeConfiguration with a base entity

后端 未结 4 981
醉梦人生
醉梦人生 2021-02-05 14:40

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

4条回答
  •  隐瞒了意图╮
    2021-02-05 14:41

    Something like this could work (untested)?

    public abstract class BaseEntityTypeConfiguration : IEntityTypeConfiguration
        where TBase : BaseEntity
    {
        public virtual void Configure(EntityTypeBuilder entityTypeBuilder)
        {
            //Base Configuration
        }
    }
    
    public class MaintainerConfiguration : BaseEntityTypeConfiguration
    {
        public override void Configure(EntityTypeBuilder entityTypeBuilder)
        {
            entityTypeBuilder.Property(b => b.CreatedDateUtc).HasDefaultValueSql("CURRENT_TIMESTAMP");
            base.Configure(entityTypeBuilder);
        }
    }
    

提交回复
热议问题