コード例 #1
0
        public void insertdepartments()
        {
            Department dept1 = new Department()
            {
                Id       = 1,
                Name     = "Developer",
                Location = "Bangalore"
            };
            Department dept2 = new Department()
            {
                Id       = 2,
                Name     = "Operations",
                Location = "Chennai"
            }; Department dept3 = new Department()

            {
                Id       = 3,
                Name     = "HR",
                Location = "Mumbai"
            };
            ModelEmployee modeldept = new ModelEmployee();

            modeldept.Departments.Add(dept1);
            modeldept.Departments.Add(dept2);
            modeldept.Departments.Add(dept3);
            modeldept.SaveChanges();
        }
コード例 #2
0
        public void insertemployees()
        {
            Employee emp1 = new Employee
            {
                Id           = 1,
                FirstName    = "Itachi",
                LastName     = "Uchiha",
                Gender       = "Male",
                Salary       = 70000,
                DepartmentId = 1
            };
            Employee emp2 = new Employee
            {
                Id           = 2,
                FirstName    = "Kakashi",
                LastName     = "Hatakae",
                Gender       = "Male",
                Salary       = 50000,
                DepartmentId = 2,
            };
            Employee emp3 = new Employee
            {
                Id           = 3,
                FirstName    = "Kushina",
                LastName     = "Uzumaki",
                Gender       = "Female",
                Salary       = 30000,
                DepartmentId = 3
            };
            Employee emp4 = new Employee
            {
                Id           = 4,
                FirstName    = "Madara",
                LastName     = "Uchiha",
                Gender       = "Male",
                Salary       = 80000,
                DepartmentId = 1
            };
            Employee emp5 = new Employee
            {
                Id           = 5,
                FirstName    = "Sakura",
                LastName     = "Haruno",
                Gender       = "Female",
                Salary       = 20000,
                DepartmentId = 2
            };
            Employee emp6 = new Employee
            {
                Id           = 6,
                FirstName    = "Hashi",
                LastName     = "Senju",
                Gender       = "Male",
                Salary       = 77000,
                DepartmentId = 3
            };
            ModelEmployee modelemp = new ModelEmployee();

            modelemp.Employees.Add(emp1);
            modelemp.Employees.Add(emp2);
            modelemp.Employees.Add(emp3);
            modelemp.Employees.Add(emp4);
            modelemp.Employees.Add(emp5);
            modelemp.Employees.Add(emp6);
            modelemp.SaveChanges();
        }