Beispiel #1
0
        public bool Save()
        {
            var affected = _context.SaveChanges();

            if (affected > 0)
            {
                return(true);
            }
            return(false);
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new CliDbExampleContext(
                       serviceProvider.GetRequiredService <DbContextOptions <CliDbExampleContext> >()))
            {
                #region Users

                context.Users.AddRange(
                    new User
                {
                    UserId       = 1,
                    FirstName    = "Ken",
                    LastName     = "Sánchez",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 2,
                    FirstName    = "Terri",
                    LastName     = "Duffy",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 3,
                    FirstName    = "Roberto",
                    LastName     = "Tamburello",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 4,
                    FirstName    = "Rob",
                    LastName     = "Walters",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 5,
                    FirstName    = "Gail",
                    LastName     = "Erickson",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 6,
                    FirstName    = "Jossef",
                    LastName     = "Goldberg",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 7,
                    FirstName    = "Dylan",
                    LastName     = "Miller",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 8,
                    FirstName    = "Diane",
                    LastName     = "Margheim",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 9,
                    FirstName    = "Gigi",
                    LastName     = "Matthew",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 10,
                    FirstName    = "Michael",
                    LastName     = "Raheem",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 11,
                    FirstName    = "Ovidiu",
                    LastName     = "Cracium",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 12,
                    FirstName    = "Thierry",
                    LastName     = "DHers",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 13,
                    FirstName    = "Janice",
                    LastName     = "Galvin",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 14,
                    FirstName    = "Michael",
                    LastName     = "Sullivan",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 15,
                    FirstName    = "Sharon",
                    LastName     = "Salavaria",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 16,
                    FirstName    = "David",
                    LastName     = "Bradley",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 17,
                    FirstName    = "Kevin",
                    LastName     = "Brown",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 18,
                    FirstName    = "John",
                    LastName     = "Wood",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 19,
                    FirstName    = "Mary",
                    LastName     = "Dempsey",
                    EmailAddress = "*****@*****.**"
                },
                    new User
                {
                    UserId       = 20,
                    FirstName    = "Wanida",
                    LastName     = "Benshoof",
                    EmailAddress = "*****@*****.**"
                }
                    );

                #endregion Users

                #region Phones

                context.Phones.AddRange(

                    new Phone {
                    PhoneId = 1, PhoneNumber = "697-555-0142", UserId = 1
                },
                    new Phone
                {
                    PhoneId     = 2,
                    PhoneNumber = "819-555-0175",
                    UserId      = 2
                },
                    new Phone
                {
                    PhoneId     = 3,
                    PhoneNumber = "212-555-0187",
                    UserId      = 3
                },
                    new Phone
                {
                    PhoneId     = 4,
                    PhoneNumber = "612-555-0100",
                    UserId      = 4
                },
                    new Phone
                {
                    PhoneId     = 5,
                    PhoneNumber = "849-555-0139",
                    UserId      = 5
                },
                    new Phone
                {
                    PhoneId     = 6,
                    PhoneNumber = "122-555-0189",
                    UserId      = 6
                },
                    new Phone
                {
                    PhoneId     = 7,
                    PhoneNumber = "181-555-0156",
                    UserId      = 7
                },
                    new Phone
                {
                    PhoneId     = 8,
                    PhoneNumber = "815-555-0138",
                    UserId      = 8
                },
                    new Phone
                {
                    PhoneId     = 9,
                    PhoneNumber = "185-555-0186",
                    UserId      = 9
                },
                    new Phone
                {
                    PhoneId     = 10,
                    PhoneNumber = "330-555-2568",
                    UserId      = 10
                },
                    new Phone
                {
                    PhoneId     = 11,
                    PhoneNumber = "719-555-0181",
                    UserId      = 11
                },
                    new Phone
                {
                    PhoneId     = 12,
                    PhoneNumber = "168-555-0183",
                    UserId      = 12
                },
                    new Phone
                {
                    PhoneId     = 13,
                    PhoneNumber = "473-555-0117",
                    UserId      = 13
                },
                    new Phone
                {
                    PhoneId     = 14,
                    PhoneNumber = "465-555-0156",
                    UserId      = 14
                },
                    new Phone
                {
                    PhoneId     = 15,
                    PhoneNumber = "970-555-0138",
                    UserId      = 15
                },
                    new Phone
                {
                    PhoneId     = 16,
                    PhoneNumber = "913-555-0172",
                    UserId      = 16
                },
                    new Phone
                {
                    PhoneId     = 17,
                    PhoneNumber = "150-555-0189",
                    UserId      = 17
                },
                    new Phone
                {
                    PhoneId     = 18,
                    PhoneNumber = "486-555-0150",
                    UserId      = 18
                },
                    new Phone
                {
                    PhoneId     = 19,
                    PhoneNumber = "124-555-0114",
                    UserId      = 19
                },
                    new Phone
                {
                    PhoneId     = 20,
                    PhoneNumber = "708-555-0141",
                    UserId      = 20
                }
                    );

                #endregion Phones

                context.SaveChanges();
            }
        }