Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement