ASP.Net Core - Entity Framework Core 2.pdf - ASP.NET Core...

This preview shows page 1 - 11 out of 25 pages.

ASP.NET Core Entity Framework Core Console Based Example
Creating the Example Project Create a new ASP.NET Console App (.NET Core) Name the project EFCoreConsole.
Adding EF Core Libraries The Microsoft.EntityFramework.Core assembly contains the core of the Entity Framework Core. But to work with EF Core, we also need to install the database provider. We need to install Microsoft.EntityFrameworkCore.SqlServer package. Since Microsoft.EntityFrameworkCore.SqlServer is dependent on Microsft.EntityFramework.Core installing it automatically installs the EF Core. We will use the NuGet Package Manager to install the Entity Framework core.
Creating Entity Class The Entity classes represent the Domain Model of the application. The EF Core builds the database based on the Entity Classes. Now, let us create a Product entity class Right click on the solutions folder and create the folder “ Models Under the Models folder right click and create the class Product.cs using System; using System.Collections.Generic; using System.Text; namespace EFExample.Models { class Product { public int Id { get; set; } public string Name { get; set; } } }
DBContext File The entity classes are managed by the DBContext API.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture