From dc3109e65be2a5275108d9cd4521a221790089a4 Mon Sep 17 00:00:00 2001 From: Vladimir Pecanac Date: Sun, 18 Oct 2026 00:08:20 +0200 Subject: [PATCH 1/2] DatabaseFirstDevelopmentWithEFCorePowerTools: move to net10.0, EF Core 10 and the EF Core 10 templates - Target net10.0. Microsoft.EntityFrameworkCore, .Design and .SqlServer 7.0.x to 10.0.13. - EfCore.SchemaCompare removed: no code uses it. - System.Security.Cryptography.Pkcs 10.0.13 referenced directly, so restore no longer reports NU1902/NU1903 for the Pkcs 9.0.11 that Microsoft.Data.SqlClient 6.1.7 brings. - T4 templates (CodeTemplates/EFCore) replaced with the EF Core Power Tools Template version 1000 set (EF Core 10). - Handlebars Imports.hbs, Properties.hbs and DbImports.hbs updated to the EF Core 10 set; Imports.hbs keeps the sample's own using line on top. - efpt.config.json and efpt.dbo2.config.json: CodeGenerationMode 3 to 6 (EF Core 10). --- .../CSharpDbContext/Partials/DbImports.hbs | 7 +++++-- .../CSharpEntityType/Partials/Imports.hbs | 4 +++- .../CSharpEntityType/Partials/Properties.hbs | 4 ++-- .../CodeTemplates/EFCore/DbContext.t4 | 20 +++++++++++++++---- .../CodeTemplates/EFCore/EntityType.t4 | 11 +++++++++- ...irstDevelopmentWithEFCorePowerTools.csproj | 10 +++++----- .../efpt.config.json | 2 +- .../efpt.dbo2.config.json | 2 +- 8 files changed, 43 insertions(+), 17 deletions(-) diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpDbContext/Partials/DbImports.hbs b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpDbContext/Partials/DbImports.hbs index 6624be1916..105acd68b6 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpDbContext/Partials/DbImports.hbs +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpDbContext/Partials/DbImports.hbs @@ -1,7 +1,10 @@ -using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; {{#if model-namespace}} using {{model-namespace}}; {{/if}} {{#each model-imports}} using {{model-import}}; -{{/each}} \ No newline at end of file +{{/each}} diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Imports.hbs b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Imports.hbs index b9a26aa64e..ea21cd0cc8 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Imports.hbs +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Imports.hbs @@ -1,4 +1,6 @@ using EFCorePowerToolsExample.Data; +using System; +using System.Collections.Generic; {{#if use-data-annotations}} using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -6,4 +8,4 @@ using Microsoft.EntityFrameworkCore; {{/if}} {{#each imports}} using {{import}}; -{{/each}} \ No newline at end of file +{{/each}} diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Properties.hbs b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Properties.hbs index 2f08d4c093..70bdc519e2 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Properties.hbs +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/CSharpEntityType/Partials/Properties.hbs @@ -2,13 +2,13 @@ {{#if property-comment}} /// - {{property-comment}} +{{property-comment}} /// {{/if}} {{#each property-annotations}} {{{property-annotation}}} {{/each}} - public {{property-type}} {{property-name}} { get; set; }{{#if nullable-reference-types }}{{#unless property-isnullable}} = null!;{{/unless}}{{/if}} + public {{property-type}} {{property-name}} { get; set; }{{#if nullable-reference-types }}{{#unless property-isnullable}} = null!;{{/unless}}{{else}}{{#if property-default-enum}} = {{property-default-enum}};{{/if}}{{/if}} {{/each}} {{#if nav-properties}} diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/DbContext.t4 b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/DbContext.t4 index ee2efb9ef3..acfda95c96 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/DbContext.t4 +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/DbContext.t4 @@ -15,8 +15,8 @@ <#@ import namespace="Microsoft.EntityFrameworkCore.Scaffolding" #> <#@ import namespace="Microsoft.Extensions.DependencyInjection" #> <# - // Template version: 703 - please do NOT remove this line - if (!ProductInfo.GetVersion().StartsWith("7.0")) + // Template version: 1000 - please do NOT remove this line + if (!ProductInfo.GetVersion().StartsWith("10.0")) { Warning("Your templates were created using an older version of Entity Framework. Additional features and bug fixes may be available. See https://aka.ms/efcore-docs-updating-templates for more information."); } @@ -28,6 +28,8 @@ var usings = new List { + "System", + "System.Collections.Generic", "Microsoft.EntityFrameworkCore" }; @@ -80,11 +82,14 @@ public partial class <#= Options.ContextName #> : DbContext if (!Options.SuppressConnectionStringWarning) { #> -#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. +#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263. <# } + + var useProviderCall = providerCode.GenerateUseProvider(Options.ConnectionString); + usings.AddRange(useProviderCall.GetRequiredUsings()); #> - => optionsBuilder<#= code.Fragment(providerCode.GenerateUseProvider(Options.ConnectionString), indent: 3) #>; + => optionsBuilder<#= code.Fragment(useProviderCall, indent: 3) #>; <# } @@ -337,6 +342,13 @@ public partial class <#= Options.ContextName #> : DbContext <# mainEnvironment = GenerationEnvironment; GenerationEnvironment = new StringBuilder(); + + WriteLine("// This file has been auto generated by EF Core Power Tools. "); + if (Options.UseNullableReferenceTypes) + { + WriteLine("#nullable enable"); + } + WriteLine(""); foreach (var ns in usings.Distinct().OrderBy(x => x, new NamespaceComparer())) { diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/EntityType.t4 b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/EntityType.t4 index 0ae779ed70..54acd31b06 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/EntityType.t4 +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/CodeTemplates/EFCore/EntityType.t4 @@ -14,7 +14,7 @@ <#@ import namespace="Microsoft.EntityFrameworkCore.Design" #> <#@ import namespace="Microsoft.Extensions.DependencyInjection" #> <# - // Template version: 703 - please do NOT remove this line + // Template version: 1000 - please do NOT remove this line if (EntityType.IsSimpleManyToManyJoinEntityType()) { // Don't scaffold these @@ -27,6 +27,8 @@ var usings = new List { + "System", + "System.Collections.Generic" }; if (Options.UseDataAnnotations) @@ -158,6 +160,13 @@ public partial class <#= EntityType.Name #> <# var previousOutput = GenerationEnvironment; GenerationEnvironment = new StringBuilder(); + + WriteLine("// This file has been auto generated by EF Core Power Tools. "); + if (Options.UseNullableReferenceTypes) + { + WriteLine("#nullable enable"); + } + WriteLine(""); foreach (var ns in usings.Distinct().OrderBy(x => x, new NamespaceComparer())) { diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools.csproj b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools.csproj index 177df8dbc9..cc89b782b3 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools.csproj +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools.csproj @@ -2,19 +2,19 @@ Exe - net7.0 + net10.0 enable enable - - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + + diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.config.json b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.config.json index 18890e7206..2d79bd02f2 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.config.json +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.config.json @@ -1,5 +1,5 @@ { - "CodeGenerationMode": 3, + "CodeGenerationMode": 6, "ContextClassName": "DBContext", "ContextNamespace": "Data", "DefaultDacpacSchema": null, diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.dbo2.config.json b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.dbo2.config.json index 924efabd4b..6380a413cd 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.dbo2.config.json +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/efpt.dbo2.config.json @@ -1,5 +1,5 @@ { - "CodeGenerationMode": 3, + "CodeGenerationMode": 6, "ContextClassName": "DBO2Context", "ContextNamespace": "Data", "DefaultDacpacSchema": null, From a622ed9caff06f23a399888d70b24fbf1158a166 Mon Sep 17 00:00:00 2001 From: Vladimir Pecanac Date: Sun, 18 Oct 2026 01:13:59 +0200 Subject: [PATCH 2/2] Power Tools: database scripts run as printed Tables.sql creates the database first and separates batches with GO, so CREATE SCHEMA dbo2 starts its own batch (it failed with Msg 111 and Msg 156). View.sql puts GO after USE so CREATE VIEW is the first statement in its batch; Function_StoredProcedure.sql puts GO between the function and the procedure. All three ran clean on SQL Server 2019 Express with sqlcmd -b. --- .../DatabaseScripts/Function_StoredProcedure.sql | 1 + .../DatabaseScripts/Tables.sql | 7 ++++++- .../DatabaseScripts/View.sql | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Function_StoredProcedure.sql b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Function_StoredProcedure.sql index 7795957802..3a8fbd9fc5 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Function_StoredProcedure.sql +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Function_StoredProcedure.sql @@ -14,6 +14,7 @@ BEGIN RETURN @Count; END; +GO CREATE PROCEDURE CountBooksInCategory_SP ( diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Tables.sql b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Tables.sql index f151bdfabe..c9045e693b 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Tables.sql +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/Tables.sql @@ -1,3 +1,6 @@ +CREATE DATABASE DatabaseFirstDevelopmentUsingEFCorePowerToolsDB +GO + USE DatabaseFirstDevelopmentUsingEFCorePowerToolsDB CREATE TABLE Authors ( @@ -26,8 +29,10 @@ CREATE TABLE Books_Categories ( FOREIGN KEY (BookID) REFERENCES Books(ID), FOREIGN KEY (CategoryID) REFERENCES Categories(ID) ); +GO -CREATE SCHEMA dbo2 +CREATE SCHEMA dbo2; +GO CREATE TABLE dbo2.Movies ( ID INT IDENTITY(1,1) PRIMARY KEY, diff --git a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/View.sql b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/View.sql index 9e41b306ee..667708d0da 100644 --- a/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/View.sql +++ b/dotnet-efcore/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseFirstDevelopmentWithEFCorePowerTools/DatabaseScripts/View.sql @@ -1,4 +1,5 @@ USE DatabaseFirstDevelopmentUsingEFCorePowerToolsDB +GO CREATE VIEW BookDetails AS SELECT