private static void CreateEmployees(IMongoCollection<Employee> collection) { var webshop = new Project() { ProjectCode = "P1", ProjectName = "Online Store" }; var secret = new Project() { ProjectCode = "P2", ProjectName = "Secret Project" }; var finance = new Project() { ProjectCode = "P3", ProjectName = "Finance System" }; var emp = new Employee() { Name = "Fernando", PhoneNumber = "1234", Projects = new List<Project> { { webshop }, { secret } } }; collection.Save(emp); emp = new SalariedEmployee() { Name = "Felipe", PhoneNumber = "5678", PayGrade = 7, Projects = new List<Project> { { secret }, { finance } } }; collection.Save(emp); emp = new Employee() { Name = "Nico", PhoneNumber = "9876", Projects = new List<Project> { { webshop }, } }; collection.Save(emp); }
static void SetupObjects() { // EMPLOYEES Employee fernando = new SalariedEmployee { EmployeeID = 1, Name = "Fernando", Username = "******", PhoneNumber = "9999", PayGrade = 7 }; Employee felipe = new HourlyPaidEmployee { EmployeeID = 2, Name = "Felipe", Username = "******", PhoneNumber = "8888", Supervisor = fernando }; Employee nico = new HourlyPaidEmployee { EmployeeID = 3, Name = "Nico", Username = "******", PhoneNumber = "7777", Supervisor = felipe }; // ADDRESSES Address ormHouse = new Address { PropertyName = "ORM House", PropertyNumber = 1, PostCode = "G4 0BA", Employees = new ArrayList4<Employee> { nico } // db4o activateable collections }; Address linqTower = new Address { PropertyName = "LINQ Tower", PropertyNumber = 9, PostCode = "KA1 1XX", Employees = new ArrayList4<Employee> { fernando, felipe } }; // SET ADDRESSES FOR EMPLOYEES fernando.Address = linqTower; felipe.Address = linqTower; nico.Address = ormHouse; // PROJECTS Project webShop = new Project { ProjectID = 1, ProjectName = "Web Shop", Employees = new ArrayList4<Employee> { felipe, nico } }; Project financeSystem = new Project { ProjectID = 2, ProjectName = "Finance System", Employees = new ArrayList4<Employee> { fernando } }; Project secret = new Project { ProjectID = 3, ProjectName = "Secret", Employees = new ArrayList4<Employee> { fernando, felipe } }; // SET PROJECTS FOR EMPLOYEES fernando.Projects = new ArrayList4<Project> { financeSystem, secret }; felipe.Projects = new ArrayList4<Project> { webShop, secret }; nico.Projects = new ArrayList4<Project> { webShop }; // OBJECT GRAPH IList<Employee> employees = new ArrayList4<Employee> { fernando, felipe, nico }; // STORE OBJECT GRAPH string dbFileName = GetDbFileName(); using (IObjectContainer db = Db4oEmbedded.OpenFile(dbFileName)) { foreach (Employee emp in employees) { db.Store(emp); } } }