首先构建IEntityTypeConfiguration<T>抽象泛型继承类KopEntityTypeConfiguration
public abstract class KopEntityTypeConfiguration<T> : IEntityTypeConfiguration<T>
创建基于 KopEntityTypeConfiguration类的 GroupMappingMap
public class GroupMappingMap : KopEntityTypeConfiguration<GroupMapping>
实现 KopEntityTypeConfiguration类的 Configure函数
public override void Configure(EntityTypeBuilder<GroupMapping> builder)
在数据上下文 ApplicationDbContext : DbContext实现的 OnModelCreating函数中,使用ModelBuilder实现应用设置
OnModelCreating函数的全部代码是
protected override void OnModelCreating(ModelBuilder builder)
{
builder.ApplyConfiguration(new GroupMappingMap());//应用设置
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
具体代码可以参考我的 ZopCommerce开源项目