Add-Migration Not Being Run .NET Core 2.0 EntityFrameworkCore 2.1.3

0
  

When doing the Add-Migration "Initial" Migration classes are not being performed, can anything be related to the connection to the database? because when I run the command no error is given, and the console prompt is available to run new command, but the migration is not completed by generating the migration files inside the Migration folder.

     

Conte CoreFactory EF Core

public class AberturaDeContasContextFactory : IDesignTimeDbContextFactory<AberturaDeContasContext>
{
    public AberturaDeContasContext CreateDbContext(string[] args)
    {
        var optionsBuilder = new DbContextOptionsBuilder<AberturaDeContasContext>();

        optionsBuilder.UseSqlServer(
            @"Data Source=3Y1S0L2;Initial Catalog=ACD;Persist Security Info=True;User ID=sa;Password=abc102030!;User Instance=False;"
        );

        return new AberturaDeContasContext(optionsBuilder.Options);
    }
}
  

Context

public class AberturaDeContasContext : DbContext
{
    public AberturaDeContasContext(DbContextOptions<AberturaDeContasContext> options)
        : base(options)
    {

    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {            
        base.OnConfiguring(optionsBuilder);
    }

    public DbSet<Parametro> Parametros { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.ApplyConfiguration(new ParametroMap());
    }
}
  

Entity Class

public class Parametro : EntityBase
{
    public Parametro()
    {

    }

    public long? ParametroId { get; set; }
    public string ChaveParametro { get; set; }
    public string ConteudoParametro { get; set; }
    public IdentificacaoValorParametro TipoValorParametro { get; set; }  
}
  

Base Class for Mapping with FluentAPI

public abstract class EntityTypeConfigurationBase<TEntity> : IEntityTypeConfiguration<TEntity>
        where TEntity : EntityBase
{
    private string _TableName;

    public virtual EntityTypeBuilder<TEntity> Config { get; set; }

    public ValueConverter ConverterGenero;
    public ValueConverter ConverterIndicador;
    public ValueConverter ConverterValores;        
    public ValueConverter ConverterDateTime;

    protected string TypeDecimal => "DECIMAL(15,2)";
    protected string TypeDate => "DATE";
    protected string TypeDateTime => "DATETIME2";
    protected string TypeSmallInt => "SMALLINT";
    protected string TypeInt => "INT";
    protected string TypeCharIndicador => "CHAR(1)";
    protected string TypeVarBinary => "VARBINARY(MAX)";
    protected string TypeText => "TEXT";

    public EntityTypeConfigurationBase(string tableName)
    {
        if (String.IsNullOrEmpty(tableName))
            throw new Exception("Nome da Tabela não informada no método construtor");

        _TableName = tableName;
    }

    public virtual void Configure(EntityTypeBuilder<TEntity> builder)
    {
        Config = builder;

        CreateConverters();

        ConfiguraTable();
        ConfiguraPrimaryKey();
        ConfiguraUniqueKeys();
        ConfiguraProperties();
        ConfigureOneToOne();
        ConfigureOneToMany();
        ConfigureManyToOne();
        ConfigureManyToMany();
        ConfigureHasData();
        ConfigureOwnsOne();
    }

    private void ConfiguraTable()
    {
        Config.ToTable(_TableName);
    }

    public abstract void ConfiguraPrimaryKey();

    public abstract void ConfiguraProperties();

    public abstract void ConfigureHasData();

    public virtual void ConfigureOwnsOne()
    {

    }

    public virtual void ConfiguraUniqueKeys()
    {

    }

    public virtual void ConfigureOneToOne()
    {

    }

    public virtual void ConfigureOneToMany()
    {

    }

    public virtual void ConfigureManyToOne()
    {

    }

    public virtual void ConfigureManyToMany()
    {

    }

    private void CreateConverters()
    {
        ConverterIndicador = new ValueConverter<bool, string>(
            x =>
            x.Equals(true) ? "S" : "N",
            x =>
            x.Equals("S") ? true : false
            );

        ConverterValores = new ValueConverter<decimal, decimal>(
            x =>
                Convert.ToDecimal(x.ToString("N2"), Culture.CultureBrazilian),
            x =>
                Convert.ToDecimal(x.ToString("N2"), Culture.CultureBrazilian)
            );

        ConverterDateTime = new ValueConverter<DateTime, DateTime>(
            x =>
                Convert.ToDateTime(x, Culture.CultureBrazilian),
            x =>
                Convert.ToDateTime(x, Culture.CultureBrazilian)
            );
    }
}
  

FluentAPI Implementation Class

public class ParametroMap : EntityTypeConfigurationBase<Parametro>
{
    public ParametroMap()
        : base("Parametro")
    {

    }

    public override void ConfiguraPrimaryKey()
    {
        Config.HasKey(x => x.ParametroId)
            .ForSqlServerIsClustered();
    }

    public override void ConfiguraProperties()
    {
        Config.Property(x => x.ChaveParametro)
            .HasMaxLength(50)
            .IsRequired();

        Config.Property(x => x.ConteudoParametro)
            .HasMaxLength(200)
            .IsRequired();

        Config.Property(x => x.TipoValorParametro)
            .HasDefaultValue(Enumerators.Enumerators.IdentificacaoValorParametro.String)
            .IsRequired();
    }

    public override void ConfiguraUniqueKeys()
    {
        Config.HasAlternateKey(x => new { x.ChaveParametro });
    }

    public override void ConfigureHasData()
    {
        Parametro Parametro1 = new Parametro
        {
            ParametroId = 1,
            ChaveParametro = "PORCENTAGEM_MINIMA",
            ConteudoParametro = "80",
            TipoValorParametro = Enumerators.Enumerators.IdentificacaoValorParametro.Double
        };

        Config.HasData(Parametro1);
    }
}
    
asked by anonymous 26.09.2018 / 21:43

0 answers