public void AddDepartment(Department department) { Departments.Add(department); department.CompanyId = Id; }
public virtual void Object_can_join_two_child_collections_using_only_parent_to_child_relation() { var company1 = new Company { Name = "Company 1" }; var company2 = new Company { Name = "Company 2" }; var employee1 = new Employee { FirstName = "Steve", LastName = "Smith", BirthDate = new DateTime(1972, 1, 2), }; var employee2 = new Employee { FirstName = "Lisa", LastName = "Johnsson", BirthDate = new DateTime(1954, 11, 12), }; var employee3 = new Employee { FirstName = "Nisse", LastName = "Karlsson", BirthDate = new DateTime(1972, 1, 3), }; var department1 = new Department("department 1"); var department2 = new Department("department 2"); var department3 = new Department("department 3"); Repository.Insert(company1, company2); company1.AddEmployee(employee1); company1.AddEmployee(employee2); company1.AddEmployee(employee3); company1.AddDepartment(department1); company1.AddDepartment(department2); company1.AddDepartment(department3); Repository.Insert(employee1, employee2, employee3); Repository.Insert(department1, department2, department3); var actualCompany1 = Repository.Find<Company>() .Where(x => x.Id == company1.Id) .Join(x => x.Employees, x => x.CompanyId) .Join(x => x.Departments, x => x.CompanyId) .ExecuteList(); Assert.AreEqual(actualCompany1, actualCompany1); }