EF Core Mapping EntityTypeConfiguration

后端 未结 15 1237
花落未央
花落未央 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 18:53

    In EF7, you override OnModelCreating on the DbContext class you're implementing.

    protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
    
            modelBuilder.Entity()
                .ForRelational(builder => builder.Table("Account"))
                .Property(value => value.Username).MaxLength(50)
                .Property(value => value.Email).MaxLength(255)
                .Property(value => value.Name).MaxLength(255);
        }
    

提交回复
热议问题