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/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
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,