예제 #1
0
        public void Attached_EnsureWeCanUseCyclicRelationsOnOwnedCollections()
        {
            Models.Manager manager;
            using (var context = new TestDbContext())
            {
                manager = context.Managers.Include(p => p.Employees).First();
                //} // Simulate disconnect

                var newEmployee = new Models.Employee {
                    Key = "assdf", FirstName = "Test Employee", Manager = manager
                };
                manager.Employees.Add(newEmployee);

                //using (var context = new TestDbContext())
                //{
                context.UpdateGraph(manager, m1 => m1.OwnedCollection(o => o.Employees));
                context.SaveChanges();
                Assert.IsTrue(context.Employees.Include(p => p.Manager).Single(p => p.Key == "assdf").Manager.FirstName == manager.FirstName);
            }
        }
예제 #2
0
        public static void SetupTheDatabase(TestContext testContext)
        {
            using (var context = new TestDbContext())
            {
                var company1 = context.Companies.Add(new Models.Company
                {
                    Name     = "Company 1",
                    Contacts = new List <Models.CompanyContact>
                    {
                        new Models.CompanyContact
                        {
                            FirstName = "Bob",
                            LastName  = "Brown",
                            Infos     = new List <Models.ContactInfo>
                            {
                                new Models.ContactInfo
                                {
                                    Description = "Home",
                                    Email       = "*****@*****.**",
                                    PhoneNumber = "0255525255"
                                }
                            }
                        }
                    }
                });

                var company2 = context.Companies.Add(new Models.Company
                {
                    Name     = "Company 2",
                    Contacts = new List <Models.CompanyContact>
                    {
                        new Models.CompanyContact
                        {
                            FirstName = "Tim",
                            LastName  = "Jones",
                            Infos     = new List <Models.ContactInfo>
                            {
                                new Models.ContactInfo
                                {
                                    Description = "Work",
                                    Email       = "*****@*****.**",
                                    PhoneNumber = "456456456456"
                                }
                            }
                        }
                    }
                });

                var project1 = context.Projects.Add(new Models.Project
                {
                    Name         = "Major Project 1",
                    Deadline     = DateTime.Now,
                    Stakeholders = new List <Models.Company> {
                        company2
                    }
                });

                var project2 = context.Projects.Add(new Models.Project
                {
                    Name         = "Major Project 2",
                    Deadline     = DateTime.Now,
                    Stakeholders = new List <Models.Company> {
                        company1
                    }
                });

                var manager1 = context.Managers.Add(new Models.Manager
                {
                    PartKey   = "manager1",
                    PartKey2  = 1,
                    FirstName = "Trent"
                });
                var manager2 = context.Managers.Add(new Models.Manager
                {
                    PartKey   = "manager2",
                    PartKey2  = 2,
                    FirstName = "Timothy"
                });

                var locker1 = new Models.Locker
                {
                    Combination = "Asdfasdf",
                    Location    = "Middle Earth"
                };

                var employee = new Models.Employee
                {
                    Manager   = manager1,
                    Key       = "Asdf",
                    FirstName = "Test employee",
                    Locker    = locker1
                };

                context.Lockers.Add(locker1);
                context.Employees.Add(employee);

                project2.LeadCoordinator = manager2;

                context.SaveChanges();
            }
        }
예제 #3
0
        public void EnsureWeCanUseCyclicRelationsOnOwnedCollections()
        {
            Models.Manager manager;
            using (var context = new TestDbContext())
            {
                manager = context.Managers.Include(p => p.Employees).First();
            } // Simulate disconnect

            var newEmployee = new Models.Employee { Key = "assdf", FirstName = "Test Employee", Manager = manager };
            manager.Employees.Add(newEmployee);

            using (var context = new TestDbContext())
            {
                context.UpdateGraph(manager, m1 => m1.OwnedCollection(o => o.Employees));
                context.SaveChanges();
                Assert.IsTrue(context.Employees.Include(p => p.Manager).Single(p => p.Key == "assdf").Manager.FirstName == manager.FirstName);
            }
        }
예제 #4
0
        public static void SetupTheDatabase(TestContext testContext)
        {
            using (var context = new TestDbContext())
            {
                var company1 = context.Companies.Add(new Models.Company
                {
                    Name = "Company 1",
                    Contacts = new List<Models.CompanyContact>
                    {
                        new Models.CompanyContact
                        {
                            FirstName = "Bob",
                            LastName = "Brown",
                            Infos = new List<Models.ContactInfo>
                            {
                                new Models.ContactInfo
                                {
                                    Description = "Home",
                                    Email = "*****@*****.**",
                                    PhoneNumber = "0255525255"
                                }
                            }
                        }
                    }
                });

                var company2 = context.Companies.Add(new Models.Company
                {
                    Name = "Company 2",
                    Contacts = new List<Models.CompanyContact>
                    {
                        new Models.CompanyContact
                        {
                            FirstName = "Tim",
                            LastName = "Jones",
                            Infos = new List<Models.ContactInfo>
                            {
                                new Models.ContactInfo
                                {
                                    Description = "Work",
                                    Email = "*****@*****.**",
                                    PhoneNumber = "456456456456"
                                }
                            }
                        }
                    }
                });

                var project1 = context.Projects.Add(new Models.Project
                {
                    Name = "Major Project 1",
                    Deadline = DateTime.Now,
                    Stakeholders = new List<Models.Company> { company2 }
                });

                var project2 = context.Projects.Add(new Models.Project
                {
                    Name = "Major Project 2",
                    Deadline = DateTime.Now,
                    Stakeholders = new List<Models.Company> { company1 }
                });

                var manager1 = context.Managers.Add(new Models.Manager
                {
                    PartKey = "manager1",
                    PartKey2 = 1,
                    FirstName = "Trent"
                });
                var manager2 = context.Managers.Add(new Models.Manager
                {
                    PartKey = "manager2",
                    PartKey2 = 2,
                    FirstName = "Timothy"
                });

                var locker1 = new Models.Locker
                {
                    Combination = "Asdfasdf",
                    Location = "Middle Earth"
                };

                var employee = new Models.Employee
                {
                    Manager = manager1,
                    Key = "Asdf",
                    FirstName = "Test employee",
                    Locker = locker1
                };

                context.Lockers.Add(locker1);
                context.Employees.Add(employee);

                project2.LeadCoordinator = manager2;

                context.SaveChanges();
            }
        }