/// <summary> /// Creates a Region object and inserts it into the DB /// </summary> /// <param name="regionId"></param> /// <param name="parentId"></param> /// <param name="name"></param> public static void InsertRegion(int regionId, int parentId, string name) { var region = new Region { Name = name, RegionId = regionId, ParentRegionId = parentId }; using (var context = new RegionsEmployeesContext()) { context.Regions.Add(region); context.SaveChanges(); } }
/// <summary> /// Creates an Employee object and inserts it into the database /// </summary> /// <param name="regionId"></param> /// <param name="name"></param> /// <param name="surname"></param> public static void InsertEmployee(int regionId, string name, string surname) { var employee = new Employee { Name = name, Surname = surname, Region = GetRegion(regionId) }; using (var context = new RegionsEmployeesContext()) { context.Employees.Add(employee); context.Regions.Attach(employee.Region); context.SaveChanges(); } }