Last active
April 24, 2020 16:50
-
-
Save robsonfaxas/c8fd85f2fb9bd50461c33d68e4a5096b to your computer and use it in GitHub Desktop.
[ASP.NET Core TW - EF Migrations] Criando Migrations com Entity Framework 2.1 #DotNetCore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adicionar pacote necessario para Migrations no EF: Microsoft.EntityFramework.Design | |
dotnet add package Microsoft.EntityFrameworkCore.Design | |
// comando de adição de migration | |
dotnet ef migrations add MigracaoInicial | |
// depois de gerada a migration, para subir ao banco de dados, utilize o comando: | |
dotnet ef database update | |
// reverter a migration criada e voltar para alguma anterior (ex.: voltar para a MigracaoInicial) | |
dotnet ef database update MigracaoInicial | |
// caso queira remover uma migration, se ela nao foi pra database ainda, pode utilizar o comando: | |
dotnet ef migrations remove | |
// Para editar tabela criada automaticamente, vá até o dbcontext e sobrescreva este método: | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.Entity<Pessoa>((builder) => { | |
builder.ToTable("PES_PESSOAS"); | |
builder.Property(p => p.Id).HasColumnName("PES_ID"); | |
builder.HasKey(p => p.Id); | |
builder.Property(p => p.Idade).HasColumnName("PES_IDADE").IsRequired(); | |
builder.Property(p => p.Nome).HasColumnName("PES_NOME").IsRequired(); | |
builder.Property(p => p.Observacoes).HasColumnName("PES_OBSERVACOES") | |
.HasMaxLength(200) | |
.IsRequired(false); | |
}); | |
modelBuilder.NamesToSnakeCase(); // verificar este método de extensão no seu gist específico | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment