Last active
May 14, 2017 16:36
-
-
Save otaviolarrosa/b790e47ec57aa3240ac14c32eededd2c to your computer and use it in GitHub Desktop.
Contexto Generico do Entity Framework.
This file contains 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
using Microsoft.EntityFrameworkCore; | |
namespace RepositoryPattern | |
{ | |
public class GenericContext<T> : DbContext where T : Entidade | |
{ | |
public DbSet<T> Entity { get; set; } | |
public GenericContext() | |
{ | |
Database.EnsureCreated();//Cria o banco de dados, caso o mesmo não exista | |
} | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
base.OnModelCreating(modelBuilder); | |
} | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
optionsBuilder.UseNpgsql("User ID=root;Password=myPassword;Host=localhost;Port=5432;Database=myDataBase;"); | |
base.OnConfiguring(optionsBuilder); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment