This article will demonstrate how to migrate the ASP.NET Core 2.2 - Bootstrap Native Project to .NET Core 3.1. Registered users can download the free ASP.NET Core 2.2 - Bootstrap Native Project and the $5 ASP.NET Core 3.1 - Bootstrap Native Project from Manage > Assets.
I used a new ASP.NET Core 3.0 Web Application (Razor Pages) project with Identity and the documentation to migrate the ASP.NET Core 2.2 - Bootstrap Native Project to .NET Core 3.0. The upgrade from .NET Core 3.0 to 3.1 was just updating the Target Framework and NuGet packages. When I upgraded KenHaggerty.Com to .NET Core 3.1 I found a couple of issues. You should migrate a copy of your project to analyze and mitigate any issues.
Let's start by editing the project file. Right click on the project then click Edit Project File.
Update the Target Framework:
Optionally remove the AspNetCoreHostingModel property if its value is InProcess:
Now use the Nuget Manager to install new packages. Right click on the project then click Manage NuGet Packages. The Microsoft.AspNetCore.Mvc.NewtonsoftJson package is required for proper Admin > Users > Details serialization. See Migrate from ASP.NET Core 2.2 to 3.0 - Json.NET support
On the Browse tab, search and install the following packages:
When I migrated KenHaggerty.Com I encountered a couple of issues, both involved the predicate in a LINQ query where clause. I was probably not using best practices as described in EF Core - Client vs. Server Evaluation, but they did not throw exceptions in ASP.NET Core 2.2 and Entity Framework Core 2.1.
The first issue was caused by casting an entity’s Enum property instead of the parameter. When MessageType is an Enum and messageTypeInt is an integer, Where(p => (int)p.MessageType == messageTypeInt) throws an exception but Where(p => p.MessageType == (MessageType)messageTypeInt) does not.
The second issue was caused by using a contains method on a populated IList<string> variable. I was using a function to return a list of article ids associated with a keyword tag. The exception stated “The LINQ expression 'Where<Article>(source: DbSet<Article>, predicate: (a) => (Unhandled parameter: __articleIds_0).Contains(a.Id))' could not be translated.” The remedy was updating the function to return List<string>.