BooksSample.Program.AddBookAsync C# (CSharp) Method

AddBookAsync() private method

private AddBookAsync ( string title, string publisher ) : System.Threading.Tasks.Task
title string
publisher string
return System.Threading.Tasks.Task
        private async Task AddBookAsync(string title, string publisher)
        {
            using (var context = new BooksContext())
            {
                var book = new Book { Title = title, Publisher = publisher };
                context.Add(book);
                int records = await context.SaveChangesAsync();

                WriteLine($"{records} record added");
            }
            WriteLine();
        }

Same methods

Program::AddBookAsync ( ) : System.Threading.Tasks.Task

Usage Example

Example #1
0
        static async Task Main()
        {
            var p = new Program();

            p.AddLogging();
            await p.CreateTheDatabaseAsync();

            await p.AddBookAsync("Professional C# 7", "Wrox Press");

            await p.AddBookAsync("Test", "Test");

            await p.AddBooksAsync();

            await QuerySamples.QueryAllBooksAsync();

            await QuerySamples.QueryAllBooksWithAsyncEnumerableAsync();

            await QuerySamples.QueryBookByKeyAsync(2);

            await p.UpdateBookAsync();

            await QuerySamples.QueryBookAsync("Professional C# 7 and .NET Core 2.0");

            await QuerySamples.FilterBooksAsync("Pro");

            await QuerySamples.UseEFFunctions("C#");

            ConflictHandling();

            await p.DeleteBookAsync(2);

            await p.QueryDeletedBooksAsync();

            await QuerySamples.QueryBooksAsync();

            QuerySamples.ClientAndServerEvaluation();
            await QuerySamples.RawSqlQuery("Wrox Press");

            QuerySamples.CompileQuery();

            await p.DeleteDatabaseAsync();
        }
All Usage Examples Of BooksSample.Program::AddBookAsync