Skip to content

Instantly share code, notes, and snippets.

@otaviolarrosa
Last active May 14, 2017 16:36
Show Gist options
  • Save otaviolarrosa/b790e47ec57aa3240ac14c32eededd2c to your computer and use it in GitHub Desktop.
Save otaviolarrosa/b790e47ec57aa3240ac14c32eededd2c to your computer and use it in GitHub Desktop.
Contexto Generico do Entity Framework.
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