コード例 #1
0
ファイル: Startup.cs プロジェクト: dpham20/cs480b
        /// <summary>
        /// Creating database table
        /// </summary>
        /// <param name="context"></param>

        private static void PopulateDatabase(QuoteContext context)
        {
            var author1 = new Author()
            {
                name = "Danny Pham"
            };
            var author2 = new Author()
            {
                name = "Turtle Kid"
            };
            var author3 = new Author()
            {
                name = "Robert Frost"
            };
            var author4 = new Author()
            {
                name = "Marylin Monroe"
            };

            var quote1 = new Quote()
            {
                quote = "I'm selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can't handle me at my worst, then you sure as hell don't deserve me at my best."
            };
            var quote2 = new Quote()
            {
                quote = "What Am I doing?"
            };
            var quote3 = new Quote()
            {
                quote = "I like Turtles."
            };
            var quote4 = new Quote()
            {
                quote = "In three words I can sum up everything I've learned about life: it goes on."
            };

            var qa1 = new QuoteAuthor()
            {
                Quote = quote1, Author = author4
            };
            var qa2 = new QuoteAuthor()
            {
                Quote = quote2, Author = author1
            };
            var qa3 = new QuoteAuthor()
            {
                Quote = quote3, Author = author2
            };
            var qa4 = new QuoteAuthor()
            {
                Quote = quote4, Author = author3
            };

            context.AddRange(qa1, qa2, qa3, qa4);

            context.SaveChanges();
        }