コード例 #1
0
        public void AddOwners(DatabaseFixture fixture)
        {
            var context = fixture.GetDbContext();

            var owners = new List <Owner>
            {
                new Owner {
                    Id = 1, FirstName = "Francisco", Surname = "Fernández", Nick = "Fran", PersonalPhoneNumber = "654987654", City = "Carmona", Country = "Spain"
                },
                new Owner {
                    Id = 2, FirstName = "Pepe", Surname = "Rodriguez", Nick = "", PersonalPhoneNumber = "456123789", City = "Ronda", Country = "Spain"
                },
                new Owner {
                    Id = 3, FirstName = "Francisco", Surname = "Rando", Nick = "Francis", PersonalPhoneNumber = "123456789", City = "Coin", Country = "Spain"
                },
                new Owner {
                    Id = 4, FirstName = "Jose", Surname = "Fernández", Nick = "Fran", PersonalPhoneNumber = "789456123", City = "Carmona", Country = "Spain"
                },
                new Owner {
                    Id = 5, FirstName = "Ignacio", Surname = "Sánchez", Nick = "Fran", PersonalPhoneNumber = "456123789", City = "Carmona", Country = "Spain"
                },
                new Owner {
                    Id = 6, FirstName = "Jorge", Surname = "Palma", Nick = "Fran", PersonalPhoneNumber = "654987654", City = "Pizarra", Country = "Spain"
                },
                new Owner {
                    Id = 7, FirstName = "Juan", Surname = "García", Nick = "Juan", PersonalPhoneNumber = "654987654", City = "Almargen", Country = "Spain"
                },
                new Owner {
                    Id = 8, FirstName = "Manuel", Surname = "Fernández", Nick = "Manu", PersonalPhoneNumber = "784596555", City = "Tebas", Country = "Spain"
                },
                new Owner {
                    Id = 9, FirstName = "Pedro", Surname = "Avila", Nick = "Peter", PersonalPhoneNumber = "654987654", City = "Campillos", Country = "Spain"
                },
                new Owner {
                    Id = 10, FirstName = "Braulio", Surname = "Perez", Nick = "", PersonalPhoneNumber = "456321789", City = "Alora", Country = "Spain"
                },
            };

            var any = context.Owners.Any(w => owners.Select(s => s.Id).ToList().Contains(w.Id));

            if (any)
            {
                return;
            }
            context.Owners.AddRange(owners);
            context.SaveChanges();
        }
コード例 #2
0
        public void AddProperties(DatabaseFixture fixture)
        {
            var context = fixture.GetDbContext();

            var properties = new List <Property>
            {
                new Property {
                    Id = 1, Name = "Villa Bonita", TownId = 1, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 1
                },
                new Property {
                    Id = 2, Name = "Villa Bonita 1", TownId = 2, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 2
                },
                new Property {
                    Id = 3, Name = "Villa Bonita 2", TownId = 3, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 1
                },
                new Property {
                    Id = 4, Name = "Villa Bonita 3", TownId = 4, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 1
                },
                new Property {
                    Id = 5, Name = "Villa Bonita 4", TownId = 5, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 2
                },
                new Property {
                    Id = 6, Name = "Villa Bonita 5", TownId = 6, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 1
                },
                new Property {
                    Id = 7, Name = "Villa Bonita 6", TownId = 7, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 1
                },
                new Property {
                    Id = 8, Name = "Villa Bonita 7", TownId = 1, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 2
                },
                new Property {
                    Id = 9, Name = "Villa Bonita 8", TownId = 2, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 1
                },
                new Property {
                    Id = 10, Name = "Villa Bonita 9", TownId = 3, DistanceAirport = 15, DistanceBeach = 18, Active = true, OwnerId = 2
                },
            };

            context.Properties.AddRange(properties);
            context.SaveChanges();
        }