Search⌘ K
AI Features

Creating a Class Library for Entity Models Using SQL Server

Explore how to create a reusable C# class library for SQL Server entity models, including setting up EF Core tools, scaffolding database tables, and configuring data annotations. Understand building separate projects for entity models and data context, adding package references, managing connection strings, and integrating with ASP.NET Core applications.

Setting up entity model for SQL Server

To use SQL Server, you will not need to do anything if we already set up the Northwind database earlier. But we will now create the entity models using the dotnet-ef tool:

Step 1: Add a new project, as defined in the following list:

  • Project template: Class Library or classlib

  • Project file and folder: Northwind.Common.EntityModels.SqlServer

  • Workspace or solution file and folder: PracticalApps

Step 2: In the Northwind.Common.EntityModels.SqlServer project, add package references for the SQL Server database provider and EF Core design-time support, as shown in the ...