SHARE
TWEET

Untitled

a guest Aug 25th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using ProductService.Models;
  2. using Microsoft.EntityFrameworkCore;
  3.  
  4.  
  5. namespace ProductService.DBContext
  6. {
  7.     public class ProductContext : DbContext, IProductContext
  8.     {
  9.         public ProductContext(DbContextOptions<ProductContext> options) : base(options)
  10.         {
  11.         }
  12.         public DbSet<Product> Products { get; set; }
  13.         public DbSet<Category> Categories { get; set; }
  14.  
  15.         protected override void OnModelCreating(ModelBuilder modelBuilder)
  16.         {
  17.             modelBuilder.Entity<Category>().HasData(
  18.                 new Category
  19.                 {
  20.                     Id = 1,
  21.                     Name = "Electronics",
  22.                     Description = "Electronic Items",
  23.                 },
  24.                 new Category
  25.                 {
  26.                     Id = 2,
  27.                     Name = "Clothes",
  28.                     Description = "Dresses",
  29.                 },
  30.                 new Category
  31.                 {
  32.                     Id = 3,
  33.                     Name = "Grocery",
  34.                     Description = "Grocery Items",
  35.                 }
  36.             );
  37.         }
  38.  
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top