Preparing the database
We will use the same blogging system used in Chapter 1, Kickstart - Introduction to Entity Framework Core. In this case, we will create SQL queries required for the existing database and then we will build our blogging system using the database-first approach. Let's write the SQL query of Blog
and Post
, which were required for the blogging system.
Blog entity script
We will create a Blog
table, then alter it to add a primary key constraint, and finally, insert some dummy data into the table. The complete script is available in the GitHub repository at https://github.com/PacktPublishing/Mastering-Entity-Framework-Core/blob/master/Chapter%202/Final/MasteringEFCore.DatabaseFirst.Final/dbo.Blog.sql.
The script required for creating the Blog
table and inserting the data is displayed as follows:
// Code removed for brevity
CREATE TABLE [dbo].[Blog] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Url] NVARCHAR (MAX) NULL
);
GO
// Code removed...