.NET 7 Entity Framework Upgrade

We have just upgraded a project from .NET 6 to .NET 7 and updated the package dependencies to Entity Framework Core.

If you do this you might get this Certificate Chain error:

This is because the latest Entity Framework Core requires the server certificate to be trusted. Add the following to your SQL Server connection string:

Trust Server Certificate=true;

Database Cursor

A database cursor allows you to loop through a set of selected records and operate on one row at a time.

Try to avoid using cursors as they sidestep the query optimisation available in SQL Server, and will run slowly. Any selection scenario can be run as SQL without using a cursor – although sometimes this will have to be Advanced SQL.

DECLARE @var int DECLARE cur CURSOR FOR SELECT Id FROM ToDoLists OPEN cur FETCH NEXT FROM cur INTO @var WHILE @@FETCH_STATUS=0 BEGIN /* do something with @var */ FETCH NEXT FROM cur INTO @var END CLOSE cur DEALLOCATE cur

Reset Identity Key

You cannot use TRUNCATE TABLE on a table that has relational constraints. So if you have an identity key and you want to reset, or insert specific key values, then you will need to use DELETE and the rather idiosyncratic DBCC CHECKIDENT function.

Usage: DBCC CHECKIDENT(<Table Name>, RESEED, <Start Seed Value>

Example:DBCC CHECKIDENT(ToDoLists, RESEED, 0)