private static void SetupDB() { using (var db = new BranchOfficeDbContext()) { db.Database.Migrate(); } }
/// <summary> /// Generate test data and save into database /// </summary> private static void GenerateTestData() { List <Employee> employees = new List <Employee>(); employees.Add(new Employee { Name = "Jan Kowalski", Email = "*****@*****.**" }); employees.Add(new Employee { Name = "Krzysztof Nowak", Email = "*****@*****.**" }); employees.Add(new Employee { Name = "Ala Jeden", Email = "*****@*****.**" }); employees.Add(new Employee { Name = "Ola Dwa", Email = "*****@*****.**" }); List <EmployeeHours> employeeHours = new List <EmployeeHours>(); employeeHours.Add(new EmployeeHours { Value = 15, TimePeriod = new TimeSpan(), Employee = employees[0] }); employeeHours.Add(new EmployeeHours { Value = 10, TimePeriod = new TimeSpan(), Employee = employees[0] }); employeeHours.Add(new EmployeeHours { Value = 12, TimePeriod = new TimeSpan(), Employee = employees[0] }); employeeHours.Add(new EmployeeHours { Value = 2, TimePeriod = new TimeSpan(), Employee = employees[2] }); Console.WriteLine("Updating database!"); using (var db = new BranchOfficeDbContext()) { db.Database.EnsureDeleted(); db.Database.Migrate(); db.Employees.AddRange(employees); var countEmployees = db.SaveChanges(); Console.WriteLine("{0} Employee records saved to database", countEmployees); db.EmployeeHoursCollection.AddRange(employeeHours); var countEmployeeHours = db.SaveChanges(); Console.WriteLine("{0} EmployeeHours records saved to database", countEmployeeHours); Console.WriteLine(); Console.WriteLine("Finished database update"); Console.WriteLine("All Employees in database:"); foreach (var employee in db.Employees) { Console.WriteLine(employee); } Console.WriteLine("All EmployeeHours in database:"); foreach (var eh in db.EmployeeHoursCollection) { Console.WriteLine(eh); } Console.WriteLine(); } }
public PostgresDataAccessObjectService(BranchOfficeDbContext dbContext) { this.dbContext = dbContext; }