• Source
    1. using System;
    2. using WPF_CRUD_EFCodeFirst_Simple.Models;
    3.  
    4. namespace WPF_CRUD_EFCodeFirst_Simple.Migrations
    5. {
    6. using System.Data.Entity.Migrations;
    7.  
    8. internal sealed class Configuration : DbMigrationsConfiguration<WPF_CRUD_EFCodeFirst_Simple.Models.ManagerDbContext>
    9. {
    10. public Configuration()
    11. {
    12. AutomaticMigrationsEnabled = false;
    13. ContextKey = "WPF_CRUD_EFCodeFirst_Simple.Models.ManagerDbContext";
    14. }
    15.  
    16. protected override void Seed(WPF_CRUD_EFCodeFirst_Simple.Models.ManagerDbContext context)
    17. {
    18. context.Departmentses.AddOrUpdate(
    19. d=>d.Name,
    20. new Departments { Id = 1 ,Name="Phòng Nhân Sự"},
    21. new Departments { Id = 2, Name="Phòng Kế Toán"},
    22. new Departments { Id = 3, Name="Phòng Hành Chính"}
    23. );
    24.  
    25. context.Employees.AddOrUpdate(
    26. e=>e.FirstName,
    27. new Employee { FirstName = "A", LastName = "Lê Văn", Birthday = new DateTime(1990,06,26), DepId = 1},
    28. new Employee { FirstName = "B", LastName = "Bùi Văn", Birthday = new DateTime(1988,01,01), DepId = 1},
    29. new Employee { FirstName = "C", LastName = "Nguyễn Thị", Birthday = new DateTime(1985,09,10), DepId = 2},
    30. new Employee { FirstName = "D", LastName = "Nguyễn Anh", Birthday = new DateTime(1989,10,25), DepId = 3},
    31. new Employee { FirstName = "E", LastName = "Phạm Ngọc", Birthday = new DateTime(1980,07,11), DepId = 3}
    32.  
    33. );
    34. }
    35. }
    36. }
    37.