public static void CreateNew100Project() { string connectionString = "port=3306;server=localhost;user id=Developer;password=holamundo;database=mytasks"; using (MySqlConnection connection = new MySqlConnection(connectionString)) { using (WorkinghoursDataContext context = new WorkinghoursDataContext(connection, false)) { var unitOfwork = new ProjectUnitOfWork(context); var firstCustomer = unitOfwork.CustomerRepository.All().First(); for (int i = 0; i < 1000; i++) { var newProject = new Project { CustomerId = firstCustomer.CustomerId, Description = "project " + i, ProjectName = "project " + i }; unitOfwork.ProjectRepository.Add(newProject); } unitOfwork.SaveChanges(); } } }
public ProjectUnitOfWork() { Context = new WorkinghoursDataContext(); ProjectRepository = new ProjectRepository(Context); CustomerRepository = new GenericRepository <IWorkinghoursDataContext, Customer>(Context); AreasRepository = new GenericRepository <IWorkinghoursDataContext, Area>(Context); UserRepository = new GenericRepository <IWorkinghoursDataContext, Users>(Context); UserRoleRepository = new GenericRepository <IWorkinghoursDataContext, UserRoles>(Context); RoleRepository = new GenericRepository <IWorkinghoursDataContext, Roles>(Context); }