
Learn to build a CRUD API with .NET Core and Entity Framework in C#, focusing on step-by-step coding along, practice, and many-to-many relationships.
Demonstrate CRUD operations in an ASP.NET Core Web API by creating, updating, and deleting countries, authors, reviewers, categories, books, and reviews, and verify cascading deletes and relationships.
Access downloadable resources for the Create ASP.NET Core Web API course, including source code and a GitHub with incremental steps. Use Udemy Q&A for questions and start coding.
Create a new ASP.NET Core web API project using the .NET Core 3.1 empty template, configure program and startup, and explore appsettings.json for the database connection string.
Create a new ASP.NET Core web application with core 2.2, start from an empty project, disable HTTPS, and configure startup and services to display Hello world in development mode.
Configure your ASP.NET Core project as an MVC app by adding and using MVC in the ConfigureServices method. Emphasize dependency injection as the core for middleware and interfaces.
Configure the project to be an mvc application by adding mvc in ConfigureServices with addMvc and enabling it in startup.cs with app.UseMvc, highlighting dependency injection.
Model a six-table book database in an asp.net core web api course, define class properties with ISBN, use database-generated IDs, and link books to authors, categories, reviews, reviewers, and countries.
Create six model classes for a book API, including book, author, reviewer, category, country, and review, with their properties and the groundwork for linking them.
Define one-to-many relationships in Entity Framework by adding navigational properties between author and country, reviewer and review, and book and review, with corresponding collections in the related classes.
Create navigational properties to define 1-to-many and many-to-many relationships, using virtual collections for lazy loading with DbContext. Link country to authors, authors to reviews, and author-to-book relationships.
Establish many-to-many links between books, authors, and categories with intermediary tables and id-based references. Configure entity relationships by adding collections and linking Book, Author, and Category with BookAuthor and BookCategory.
Create intermediary classes BookAuthor and BookCategory to link books with authors and categories using BookId, AuthorId, and CategoryId, with navigation properties for Entity Framework relationships.
Learn how entity framework maps books, authors, reviews, categories to tables using keys and foreign keys, with one-to-many and many-to-many relationships via intermediary tables such as BookAuthor and BookCategory.
Leverage data annotations to mark primary keys, enforce required fields, limit string length, and specify database generated identities in an ASP.NET Core Web API using Entity Framework.
Apply data annotations to all properties, enforce a database generated id, validate name and category to 50 characters with custom messages, and ensure review and reviewer fields with proper ranges.
Apply data annotations to define keys, required fields, and character limits in an asp.net core web api, including identity fields and validation messages, and generate database tables from the models.
Follow a code-first approach to create a database from your classes, then install and configure entity framework core packages (tools, server, design-time components) to enable migrations and updating the database.
Install the .NET core 2.2 NuGet packages, using the code-first approach to database creation, and install Microsoft.Aspnetcore.all while removing Razor, ensuring all libraries are in place.
Configure entity framework by wiring a database connection string from an injected configuration interface in the startup. Store the string in appsettings.json and prepare the DbContext for EF usage.
Inject a DbContext-derived class into services, create a BookContext, and define virtual DbSets for books, authors, reviews, categories, countries, and the book author and book category relations to enable migrations.
override OnModelCreating in DbContext to define many-to-many relationships between books, categories, and authors using ModelBuilder, with keys and foreign keys in the BookCategory and BookAuthor junction tables.
Use ModelBuilder to create a BookAuthor intermediary entity with book id and author id keys. Establish a bidirectional many-to-many relationship between authors and books in the BookAuthor table.
Create a BookAuthor intermediary entity in ModelBuilder, define BookId and AuthorId as keys, and establish relationships from author and book to BookAuthor.
Configure the startup to use the book context, add an Entity Framework migration, create the database, run update-database, and seed the initial data.
Seeding the database uses a static class DbSeedingClass with a static extension method SeedDataContext on BookDbContext to populate books, authors, categories, reviews, reviewers, and countries via AddRange and SaveChanges.
Seed the database in a .NET core 3.1 app at startup, then map controllers to endpoints and verify linked data across books, authors, countries, categories, and reviews.
Run SeedDataContext at startup to populate authors, books, categories, and reviews. Verify data integrity and prevent reseeding by commenting out the seed call and fix DbSet naming to countries.
Explore creating api calls for a book catalog, focusing on get endpoints such as api/books and api/books/{id}. Review accompanying endpoints for isbn, ratings, authors, categories, countries, reviewers, and reviews.
Explore dependency injection and inversion of control in ASP.NET Core by wiring interfaces to implementations via a container, decoupling controllers, and wiring services in startup for CRUD with DbContext.
Define an ICountryRepository interface in the services folder for an ASP.NET Core Web API, with four methods: GetCountries, GetCountry(int countryId), GetCountryOfAnAuthor(int authorId), and GetAuthorsFromACountry(int countryId).
Implement the ICountryRepository in a new CountryRepository, inject BookDbContext, and implement GetCountries and GetCountry by Id to query and order the countries by name, returning null when not found.
Implement get country of an author by querying authors and selecting the related country, using first or default, and add methods for authors by country and country existence checks.
Create a countries controller and inject ICountryRepository to expose a GetCountries API at api/countries, returning a list of countries with an ok status.
Learn to test the GetCountries API in a step-by-step asp.net core web api course, using postman, running with ctrl+F5, and fixing dependency injection by registering CountryRepository in startup.
Register the ICountryRepository service in an asp.net core web api project using add scoped, wire the interface to its repository implementation, and use data transfer objects to simplify country data.
Create a country dto with id and name, place it in a dtos folder, omit author data, and wire return of these properties via the controller.
Refactor the GetCountries action to return country dto objects with only id and name by mapping from existing data, validate model state, and annotate for 200 and 400 responses.
Create a get country api endpoint that retrieves a single country by id, using httpget with a countryId route parameter, validating existence and returning a countryDto or not found.
Create an api action GetCountryOfAnAuthor to fetch an author's country by author id, validate the author exists, and return a country dto with appropriate status codes.
Implement ICategoryRepository and CategoryRepository, wire the DbContext, and expose GetCategories and GetCategory (GetCategoriesOfABook will be added later). Add a category DTO with Id and name and register services in startup.
Define ICategoryRepository with methods to get all categories, get a category by id, get categories for a book, and get all books in a category.
Finish implementing ICategoryRepository by adding GetAllCategoriesForABook using the BookCategories DbSet to map a book to its categories in a many-to-many relationship. Also implement GetAllBooksForACategory in reverse and add CategoryExists.
Create a categories controller in asp.net core web api, inject the category repository, and implement a get all categories action returning a category dtl (id and name) via api/categories.
Implement a GetAllCategoriesForABook API in the categories controller to return a list of CategoryDto for a given bookId, using a repository method and proper model state validation.
Create remaining DTO classes for reviewer, review, author, and book, following existing conventions and returning only properties directly related to each object for your ASP.NET Core Web API.
Learn to create remaining dto classes for book, author, review, and reviewer with id, isbn, title, and date published, in the dtos folder, and implement interfaces with get methods.
Develop repository interfaces for reviewer, review, author, and book with methods to get by id or ISBN, check existence and duplicates, and calculate book ratings from reviews.
Introduce the IBookRepository interface in a services folder for asp.net core web api, enabling retrieval of all books, by id or isbn, and rating, plus existence and duplicate isbn checks.
Define the IAuthorRepository interface in the services folder to expose methods to fetch authors, a single author, authors by book, books by author, and author existence.
Define the IReviewerRepository interface with methods GetReviewers, GetReviewer, GetReviewsByReviewer, GetReviewerOfAReview, and a reviewer existence check to support querying reviewers and their reviews.
Define the IReviewRepository interface with methods to get all reviews, a review by id, reviews for a book, the book of a review, and existence checks, using DTOs.
Implement a get authors from a country endpoint in the countries controller at api/countries/{countryId}/authors, validate the country, map authors to author dto, and return a 200 response or errors.
Implement the get all books for a category endpoint by validating the category, retrieving books via the category repository, mapping them to book dto, and returning 200 status.
Implement the IReviewerRepository interface by adding GetReviewers, GetReviewer, GetReviewerOfAReview, and GetReviewsByReviewer using Dto objects, then register services in startup and expose them in the API controller with validation.
Implement the IReviewerRepository interface by creating ReviewerRepository, inject BookDbContext, and implement methods to check existence, list, and fetch reviewers and their reviews for use in a controller.
Create a get reviewers api in an ASP.NET Core web api by building a reviewers controller, injecting a reviewer repository, and returning a detailed reviewer list at api/reviewers.
Implement GetReviewer action at api/reviewers/{reviewerId} to fetch a reviewer, validate existence, return 404 if not found, map to ReviewerDto with id, first name, last name, and return 200.
Implement the GetReviewsByReviewer action to fetch reviews for a reviewer, validate the reviewer, map to ReviewDto, and return 200 with the list or 404/400 errors.
Implement the get reviewer of a review API in ASP.NET Core by injecting IReviewRepository, validating ReviewExists, calling GetReviewerOfAReview, and returning a reviewerDto at api/reviewers/{reviewId}/reviewer with 200, 400, and 404 results.
Implement the IReviewRepository interface and API endpoints for GetReviews, GetReview, GetBookOfAReview, and GetReviewsForABook using the reviews data set. Create controller actions and register service in Startup.cs, following the ReviewerRepository pattern.
Implement the IReviewRepository in a new review repository class and inject the book context. Build methods to check existence, get all reviews, and fetch a book with its reviews.
Create a reviews API by adding a ReviewsController, injecting IReviewRepository and IReviewerRepository, and implementing GetReviews to return a ReviewDto list at api/reviews, ordered by rating.
implement the getreview API in the reviews controller by validating reviewId, querying the review repository, and returning a reviewDto (id, headline, rating, reviewText) with 200 ok or 404 not found.
Create GetReviewsForABook in ReviewsController by adapting GetReviewsByReviewer, expose api/reviews/books/{bookId}, and return a reviewsDto list from the repository.
Create GetBookOfAReview API in reviews controller to return a bookDto for a given reviewId at the /book route. Validate with a book repository and test not found responses via Postman.
Implement the author repository interface and API to retrieve authors and their books using the BookAuthors intermediary, returning lists and exposing a new controller with startup.cs service registration.
Implement the IAuthorRepository interface in an alpha repository and inject the DbContext. Retrieve authors and book offers via the many-to-many book offers table, exposing get operations for books.
Create an AuthorsController that injects IAuthorRepository and implement the GetAuthors action to return an IEnumerable<AuthorDto> at api/authors, mapping each author’s id, firstName, and lastName, then test with postman.
Create an api endpoint that returns an author dto by author id, validating existence with the author repository and returning 200 with the author details or 404 if not found.
Implement the get books by author API: validate author existence, retrieve and map books to book dto, and return 200, 400, or 404 as appropriate.
Implement GetAuthorsOfABook API to fetch all authors for a given book by bookId, returning IEnumerable<AuthorDto> and validating the book exists via IBookRepository.
Welcome to Creating CRUD API in Asp .Net Core and Entity Framework Core.
As the title of the course suggests, we will be creating an API that will handle Creating, Reading, Updating and Deleting records from a database with the help of .Net Core and Entity Framework.
This course is all about CRUD operations. Step by step, we will set up a complete API to handle each of the operations in a multi-table database. For the next several hours, we will dedicate our time to interfaces, dependency injection, 1 to many and many to many database relationships, .Net Core Services, Models, Data Transfer Objects, Controllers and Actions, and of course, C# language. But don’t let any of that scare you. Quite the opposite.
Get excited to learn a ton of new material and dive into the new world of .Net core. The course makes the learning easy with the mix of slow introduction of new material, repetition, and lot of practice! Every line of code is coded on camera, there are no mysteriously appearing blocks of code. Every step is explained every time, not just the first time you are introduced to it. And you will have a chance to practice what you learned in homework assignments.
Let’s go over few details. First, let’s discus what this course IS
Introduction to creating CRUD API using Asp .net Core and Entity Framework.
We go over complete creation of CRUD API
I introduce new concepts as they are needed in regards to progression of the project
This is a “follow along” and “practice what you learned” course
No code is skipped over.
What this course is NOT:
Complete or Deep Dive course
Learn C# or .net core course
Theory with explanation and code snippets
Ready to Deploy Real World project
1. API are a huge subject, and so is net core and so is Entity Framework. In this course we will create a CRUD Web API in .Net Core. Nothing more, nothing less. Do not expect a dive into security, database optimization, asynchronous processing or anything else. Just CRUD. Pure and simple. We will work only with C# language inside .net core. So do not expect any javascript or fancy javascript framework or library. There is none in this course. But don’t expect to use this course as a “Learn C# course”. It is not that. I’m sure you will pick up some new syntax and C# tricks, but you do need some C# skills prior to taking this course. The project we use is a great starting point as it introduces several of the essential techniques and concepts, including often neglected CRUD operations on database tables with many-to-many relationships, this certainly isn’t a deploy-ready project.
2. Remember, this is a course, and a practical tutorial. There are lot of courses that will show you the way into one topic and then quickly move on to another topic. This is not one of those courses! My goal is to lead you step by step, all the way, through the new territory inside .Net core and introduce you to new concepts and topics and help you learn them. And equally important is to then help you understand and retain what you learned through practice and repetition. If you prefer to be shown something once and then jump to another topic, then this course is NOT for you. If, on the other hand, you learn by combining explanation, coding along, and practicing the concepts while still having the option to see the instructor coding the whole solution, then this course is definitely for you!
3. Did this ever happen to you? You took a course, and you just loved it! Everything was clearly explained, and you had lots of aha moments. Then the course ended…and suddenly, you felt lost. You felt like you learned so much while taking the course, yet could barely remember anything once it ended. Even when you revisited the source code supplied by the instructor, it just didn’t even seem familiar. Suddenly you felt like you didn’t learn anything. All the concepts that seemed so clear during the course felt totally foreign when you were on your own. In my experience, this is often the case when you simply take a course that starts exactly where your current skills are, but moves past the threshold of skills you are ready for. Like trying to go from crawling straight to sprinting. In this course, we go step by step, introducing new concepts slowly and only after you had a chance to practice what you learned.
4. is this course for you? What skills should you have before taking it? If you are a programmer with decent understanding of OOP principles and C#, than you have the all the skills needed to benefit from this course. There are no prerequisites for .net core, or entity framework or how to create an API. Since you are interested in this course, I assume you heard of these things and perhaps played around a little too. That’s all that is needed to take this course.
Well, let's code!