コード例 #1
0
        private static void PopulateDatabase(quoteableDbContext context)
        {
            var author1 = new Author()
            {
                FirstName = "Dr",
                LastName  = "Seuss"
            };
            var author2 = new Author()
            {
                FirstName = "Mr",
                LastName  = "Spock"
            };
            var author3 = new Author()
            {
                FirstName = "Mr",
                LastName  = "Tuvok"
            };

            var document1 = new quote();

            document1.Quotes = "Green Eggs and Ham";

            var document2 = new quote();

            document2.Quotes = "Vulcan, A Primer";

            var document3 = new quote();

            document3.Quotes = "Green Eggs and Vulcans";

            var da1 = new quoteAuthor()
            {
                Quote = document1, Author = author1
            };
            var da2 = new quoteAuthor()
            {
                Quote = document2, Author = author2
            };
            var da3 = new quoteAuthor()
            {
                Quote = document3, Author = author1
            };
            var da4 = new quoteAuthor()
            {
                Quote = document3, Author = author2
            };
            var da5 = new quoteAuthor()
            {
                Quote = document3, Author = author3
            };

            context.AddRange(da1, da2, da3, da4, da5);

            context.SaveChanges();
        }