markjprice / cs12dotnet8

Repository for the Packt Publishing book titled "C# 12 and .NET 8 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
564 stars 164 forks source link

Compatibility issues when trying to work through EF functionality. #33

Closed BoredNumb closed 4 months ago

BoredNumb commented 4 months ago

First of all, I have little to complain about with the book. I'm learning quite a bit in trying to update my C# version.

I am running into issues when I try to work through Chapters 10 and 13. I'm using:

VS2022 SQL Server 2019 (located on my local machine)

I'll use the Chapter 10 instructions to show what is happening.

I follow along with the online instructions for SQL Server. I've installed the Northwind database and I'm building the solution. I created the initial solution (WorkingWithEFCore) and the instructions want me to add the using for System.Console and the references to Microsoft.Data.SqlClient and Microsft.EntityFrameworkCore.SqlServer. I building the project fails with a warning that the Microsoft.Data.SqlClient version 5.1.1 is a vulnerable package and that System.Security.Cryptography.Cng version 5.0.0 not being compatible with net8.0. There is a similar conflict with System.Windows.Extensions version 6.0.0.

I'm guessing that the Microsoft.Data.SqlClient library or the Microsoft.EntityFrameworkCore.SqlServer relies on the offending libraries but I'm not sure how to resolve the problem. I could work through the exercises with the vulnerable libraries if the project built but that wouldn't help much in the end as the reason I'm updating my knowledge is that I need to update a couple of projects for work and having the vulnerable library would not be permitted.

Any ideas on how I can move forward with this? Thanks!

markjprice commented 4 months ago

Visual Studio 2022 advises you to upgrade to 5.2.0, as shown in the screenshot. Just do that. image

markjprice commented 4 months ago

I have updated the appropriate page in the GitHub repo: https://github.com/markjprice/cs12dotnet8/blob/main/docs/sql-server/README.md#defining-the-northwind-database-context-class

I've also added an improvement item for this: https://github.com/markjprice/cs12dotnet8/blob/main/docs/errata/improvements.md#page-517---using-sql-server-or-other-sql-systems

BoredNumb commented 4 months ago

The dependencies are resolved but now the scaffolding command returns the following error:

Your startup project 'Northwind.EntityModels.SqlServer' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

I added

to the project file as well and this corrected my issue.

markjprice commented 4 months ago

Yes, the instructions to add Microsoft.EntityFrameworkCore.Design are in the book and apply to both SQLite and SQL Server. In the next edition, I will add a note in the book to explicitly say this, although hopefully it is implied that SQL Server users must complete everything in the book except when explicitly about SQLite.