示例#1
0
 static void RemoveItem(Context context)
 {
     var employee = context.Employees.FirstOrDefault(e => e.Name.StartsWith("A"));
     if (employee != null)
     {
         context.Employees.Remove(employee);
         context.SaveChanges();
     }
 }
示例#2
0
        static void AddItems(Context context)
        {
            var departmentSD = new Department { Name = "Software development" };
            var departmentHR = new Department { Name = "HR" };
            context.Departments.Add(departmentSD);
            context.Departments.Add(departmentHR);

            context.Employees.Add(new Employee { Name = "Sergey Efremov", Department = departmentSD });
            context.Employees.Add(new Employee { Name = "Andrey Ivanov", Department = departmentHR });
            
            context.SaveChanges();
        }
示例#3
0
 static void EditItem(Context context)
 {
     var employee = context.Employees.First(e => e.Name.StartsWith("A"));
     employee.Name = "Sergey";            
     context.SaveChanges();
 }