EF Core Mapping EntityTypeConfiguration

后端 未结 15 1238
花落未央
花落未央 2020-11-30 18:26

In EF6 we usually able to use this way to configure the Entity.

public class AccountMap : EntityTypeConfiguration
{
    public AccountMap()
           


        
15条回答
  •  一整个雨季
    2020-11-30 19:02

    Am I right?

    public class SmartModelBuilder where T : class         {
    
        private ModelBuilder _builder { get; set; }
        private Action> _entityAction { get; set; }
    
        public SmartModelBuilder(ModelBuilder builder, Action> entityAction)
        {
            this._builder = builder;
            this._entityAction = entityAction;
    
            this._builder.Entity(_entityAction);
        }
    }   
    

    I can Pass config:

     protected override void OnModelCreating(ModelBuilder builder)
        {
            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);
    
    
    
            new SmartModelBuilder(builder, entity => entity.Property(b => b.Url).Required());
    
        } 
    

提交回复
热议问题