• Source
    1. using System;
    2. using System.Data.Entity.Migrations;
    3. using System.Runtime.Remoting.Contexts;
    4.  
    5. namespace ExampleCodeFirst
    6. {
    7. static class Program
    8. {
    9. static void Main(string[] args)
    10. {
    11. var dep1 = new Departments { Name = "Phong Ke Hoach" };
    12. var dep2 = new Departments { Name = "Phong Nhan Su" };
    13.  
    14. var em1 = new Employee { FirstName = "A", LastName = "Le Minh", Birthday = Convert.ToDateTime("26/06/1987"), DepId = 1 };
    15. var em2 = new Employee { FirstName = "B", LastName = "Nguyen Van", Birthday = Convert.ToDateTime("12/05/1981"), DepId = 1 };
    16. var em3 = new Employee { FirstName = "C", LastName = "Tran Thi", Birthday = Convert.ToDateTime("21/09/1985"), DepId = 2 };
    17. var em4 = new Employee { FirstName = "D", LastName = "Phan Van", Birthday = Convert.ToDateTime("06/02/1990"), DepId = 2 };
    18.  
    19.  
    20. using (var context = new ManagerDbContext())
    21. {
    22. context.Departmentses.Add(dep1);
    23. context.Departmentses.Add(dep2);
    24.  
    25. context.Employees.Add(em1);
    26. context.Employees.Add(em2);
    27. context.Employees.Add(em3);
    28. context.Employees.Add(em4);
    29.  
    30. context.SaveChanges();
    31. Console.WriteLine("Success !\n");
    32. Console.WriteLine("Departmentses Info:\n");
    33. foreach (var dep in context.Departmentses)
    34. {
    35. Console.WriteLine(dep.Id + "\t" + dep.Name);
    36. }
    37.  
    38. Console.WriteLine("\nListing of all employees: \n ");
    39. foreach (var em in context.Employees)
    40. {
    41. Console.WriteLine(em.Id + '\t' + em.FirstName + " " + em.LastName + '\t' + em.Birthday + '\t' + em.Departments.Name);
    42. }
    43. }
    44.  
    45. Console.ReadLine();
    46. }
    47. }
    48. }
    49.