BaseEntityTypeConfiguration.cs 1.1 KB
Newer Older
S
simon 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33


using Aurora.Common.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;

namespace Aurora.Core.EntityFramework.EntitiesConfig
{
    /// <summary>
    /// 对父类领域实体配置
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class BaseEntityTypeConfiguration<T> : IEntityTypeConfiguration<T>
        where T : class, ITenantEntity
    {
        public void Configure(EntityTypeBuilder<T> builder)
        {
            builder.Property(x => x.TenantCode).HasMaxLength(100);
            builder.HasKey(x => new { x.TenantCode, x.ID });
            // builder.HasIndex(x => new { x.TenantCode, x.ID });
            // builder.Property(x => x.RowCreatedBy).HasMaxLength(100);
            // builder.Property(x => x.RowUpdatedBy).HasMaxLength(100);
            Map(builder);
        }

        /// <summary>
        /// 强行让子类实现自己配置
        /// </summary>
        /// <param name="builder"></param>
        public abstract void Map(EntityTypeBuilder<T> builder);
    }
}