Skip to content

Instantly share code, notes, and snippets.

@AndyWatt83
Created December 6, 2021 23:22
Show Gist options
  • Save AndyWatt83/ffd01e29a6f5b25bb317ca2a8744009a to your computer and use it in GitHub Desktop.
Save AndyWatt83/ffd01e29a6f5b25bb317ca2a8744009a to your computer and use it in GitHub Desktop.
A data context for a very simple entity framework example
using Blog.Database.Entities;
using Microsoft.EntityFrameworkCore;
namespace Blog.Database;
public class AppDbContext : DbContext
{
public DbSet<BlogPost> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseNpgsql("Host=postgres;Database=blog_database;Username=docker_user;Password=password");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BlogPost>().HasData(
new BlogPost() { Id = 1, Title = "Doing Docker" },
new BlogPost() { Id = 2, Title = "Angular with Docker" },
new BlogPost() { Id = 3, Title = "Addicted to Docker - send help" }
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment