Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Install entity framework core in class library project

Suggested Videos
Part 25 - Pass parameters to view component in core | Text | Slides
Part 26 - ASP.NET Core view component tag helper | Text | Slides
Part 27 - Implement search page in ASP.NET Core | Text | Slides

In this video we will discuss how to install Entity Framework Core in a separate .NET standard class library project.

So far our application has been working with in memory data. We want to use SQL Server as the database for our application. So let's install entity framework core.

In most real world applications, data access services are usually present in a separate reusable class library project. Install the following 3 nuget packages to install entity framework core.
  1. Microsoft.EntityFrameworkCore
  2. Microsoft.EntityFrameworkCore.SqlServer
  3. Microsoft.EntityFrameworkCore.Tools
In the application that we have been working with so far in this video series, we have a project with name RazorPagesTutorial.Services. This is our data access project. So, in the solution explorer, right click on the project name and select "Manage NuGet Packages" from the context menu and install the following 3 packages.

Microsoft.EntityFrameworkCore As the name implies contains the core entity framework services.
Microsoft.EntityFrameworkCore.SqlServer Contains the services that lets us use SQL server as the database. This is called the database provider package. If you want to use MySQL as the database instead, then install Pomelo.EntityFrameworkCore.MySql provider package. For each database provider, there is usually a seprate provider specific nuget package which you may have to search for and install.
Microsoft.EntityFrameworkCore.Tools This nuget package contains Package Manager Console tools and commands like Add-Migration, Update-Database etc. We use these commands to create and execute EF Core migrations. We will discuss migrations in our upcoming videos.

NU1605 detected package downgrade

If you get this error, the most likely cause is you have multiple projects in your solution and in one of the projects you just installed a NuGet package. There is already an older version of this same nuget package in one of the other projects in the solution. When you double click on the error, it takes you to the project file that contains the older version of the NuGet package. The obvious fix is to upgrade that NuGet package to the latest version and the error should go away,

In my case the exact error is the following
NU1605 Detected package downgrade: Microsoft.EntityFrameworkCore from 3.1.1 to 3.0.0. 

What caused the above error
In one of the projects, I already had Microsoft.EntityFrameworkCore 3.0.0 installed. In the same solution, in another project, I just installed Microsoft.EntityFrameworkCore 3.1.1 package and then I have the above Detected package downgrade error.

To fix this I have to upgrade Microsoft.EntityFrameworkCore from 3.0.0 to 3.1.1 core tutorial for beginners

No comments:

Post a Comment

It would be great if you can help share these free resources