Ejemplo n.º 1
0
 private static async Task CreateBooksAsync()
 {
     using var context = new BooksContext();
     context.Books.Add(new Book {
         Title = "Professional C# 7", Publisher = "Wrox Press", Isbn = "4737834"
     });
     context.Books.Add(new Book {
         Title = "Professional C# 6", Publisher = "Wrox Press", Isbn = "343454"
     });
     await context.SaveChangesAsync();
 }
Ejemplo n.º 2
0
        private async Task AddBookAsync(string title, string publisher)
        {
            using (var context = new BooksContext())
            {
                Book book = new Book {
                    Title = title, Publisher = publisher
                };
                await context.Books.AddAsync(book);

                int records = await context.SaveChangesAsync();

                Console.WriteLine($"{records} record added");
            }
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        private async Task AddBooksAsync()
        {
            using (var context = new BooksContext())
            {
                var b1 = new Book {
                    Title = "Professional C# 6 and .NET Core 1.0", Publisher = "Wrox Press"
                };
                var b2 = new Book {
                    Title = "Professional C# 5 and .NET 4.5.1", Publisher = "Wrox Press"
                };
                var b3 = new Book {
                    Title = "JavaScript for Kids", Publisher = "Wrox Press"
                };
                var b4 = new Book {
                    Title = "Web Design with HTML and CSS", Publisher = "For Dummies"
                };
                await context.Books.AddRangeAsync(b1, b2, b3, b4);

                int records = await context.SaveChangesAsync();

                Console.WriteLine($"{records} records added");
            }
            Console.WriteLine();
        }