Skip to content

Commit

Permalink
Upgrade to EF Core 9.0 (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysneed authored Nov 26, 2024
1 parent 4a47740 commit d4f974c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 61 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht

## Prerequisites

- [Visual Studio 2022](https://www.visualstudio.com/downloads/) or greater, [JetBrains Rider](https://www.jetbrains.com/rider) 2022.2 or greater.
- [.NET 8.0 SDK](https://dotnet.microsoft.com/download/dotnet) or greater.
- [EF Core CLI 8.0](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) or greater.
- [Visual Studio 2022](https://www.visualstudio.com/downloads/) or greater, [JetBrains Rider](https://www.jetbrains.com/rider) 2024.3 or greater.
- [.NET 9.0 SDK](https://dotnet.microsoft.com/download/dotnet) or greater.
- [EF Core CLI 9.0](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) or greater.
- Install global `dotnet-ef` tool.
```
dotnet tool install --global dotnet-ef
Expand Down Expand Up @@ -54,10 +54,10 @@ docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=MyPass@word" -e "MSSQL_PID=D
## Upgrading
1. Upgrade `TargetFramework` in **.csproj** file to `net8.0`.
1. Upgrade `TargetFramework` in **.csproj** file to `net8.0` or `net9.0`.
- Optional: Set `ImplicitUsings` to `enable`.
- Optional: Set `Nullable` to `enable`.
2. Update the following NuGet packages to `8.0.0` or later:
2. Update the following NuGet packages to `9.0.0` or later:
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.SqlServer
- EntityFrameworkCore.Scaffolding.Handlebars
Expand All @@ -69,7 +69,7 @@ docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=MyPass@word" -e "MSSQL_PID=D
## Usage
1. Create a new **.NET 8** class library.
1. Create a new **.NET 8** or **.NET 9** class library.
2. Add EF Core SQL Server and Tools NuGet packages.
- `Microsoft.EntityFrameworkCore.SqlServer`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 10 additions & 4 deletions sample/ScaffoldingSample/Contexts/NorthwindSlimContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
if (!optionsBuilder.IsConfigured)
{
#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.
optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=NorthwindSlim; Integrated Security=True;");
optionsBuilder.UseSqlServer("Server=localhost; Database=NorthwindSlim; User ID=sa;Password=MyPass@word; TrustServerCertificate=True;");
}
}

Expand All @@ -55,7 +55,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
entity.ToTable("Customer");

entity.Property(e => e.CustomerId).HasMaxLength(5);
entity.Property(e => e.CustomerId)
.HasMaxLength(5)
.IsFixedLength();

entity.Property(e => e.City).HasMaxLength(15);

Expand All @@ -73,7 +75,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

entity.ToTable("CustomerSetting");

entity.Property(e => e.CustomerId).HasMaxLength(5);
entity.Property(e => e.CustomerId)
.HasMaxLength(5)
.IsFixedLength();

entity.Property(e => e.Setting).HasMaxLength(50);

Expand Down Expand Up @@ -120,7 +124,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
entity.ToTable("Order");

entity.Property(e => e.CustomerId).HasMaxLength(5);
entity.Property(e => e.CustomerId)
.HasMaxLength(5)
.IsFixedLength();

entity.Property(e => e.Freight)
.HasColumnType("money")
Expand Down
4 changes: 2 additions & 2 deletions sample/ScaffoldingSample/ScaffoldingSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>8.0.0</Version>
<Version>9.0.0-beta1</Version>
<Authors>Tony Sneed</Authors>
<Company>Tony Sneed</Company>
<Title>Entity Framework Core Scaffolding with Handlebars</Title>
Expand All @@ -12,28 +12,30 @@
<PackageProjectUrl>https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>scaffolding reverse-engineer entity-framework-core handlebars</PackageTags>
<PackageReleaseNotes>See: https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars/releases/tag/v8.0.0</PackageReleaseNotes>
<PackageReleaseNotes>See: https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars/releases/tag/v9.0.0-beta1</PackageReleaseNotes>
<LangVersion>latest</LangVersion>
<IncludeSource>true</IncludeSource>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<FileVersion>8.0.0.0</FileVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<FileVersion>9.0.0.0</FileVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Handlebars.Net" Version="2.1.2" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<Content Include="EntityFrameworkCore.Scaffolding.Handlebars.targets" PackagePath="build/EntityFrameworkCore.Scaffolding.Handlebars.targets" />
<Content Include="CodeTemplates/**/*.*" Pack="true" PackagePath="lib/net8.0/CodeTemplates">
<PackageCopyToOutput>true</PackageCopyToOutput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,9 @@ public virtual ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationOp
options.SuppressOnConfiguring);

var dbContextFileName = ContextTransformationService.TransformContextFileName(options.ContextName) + FileExtension;
resultingFiles.ContextFile = new ScaffoldedFile
{
Path = options.ContextDir != null
? Path.Combine(options.ContextDir, dbContextFileName)
: dbContextFileName,
Code = generatedCode
};
resultingFiles.ContextFile = new ScaffoldedFile(options.ContextDir != null
? Path.Combine(options.ContextDir, dbContextFileName)
: dbContextFileName, generatedCode);
}

if (!(CSharpEntityTypeGenerator is NullCSharpEntityTypeGenerator))
Expand All @@ -177,11 +173,7 @@ public virtual ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationOp
? Path.Combine(CSharpHelper.Namespace(schema), transformedFileName + FileExtension)
: transformedFileName + FileExtension;
resultingFiles.AdditionalFiles.Add(
new ScaffoldedFile
{
Path = entityTypeFileName,
Code = generatedCode
});
new ScaffoldedFile(entityTypeFileName, generatedCode));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,9 @@ public virtual ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationOp
options.SuppressOnConfiguring);

var dbContextFileName = ContextTransformationService.TransformContextFileName(options.ContextName) + ".cs";
resultingFiles.ContextFile = new ScaffoldedFile
{
Path = options.ContextDir != null
? Path.Combine(options.ContextDir, dbContextFileName)
: dbContextFileName,
Code = generatedCode
};
resultingFiles.ContextFile = new ScaffoldedFile(options.ContextDir != null
? Path.Combine(options.ContextDir, dbContextFileName)
: dbContextFileName, generatedCode);
}

if (!(CSharpEntityTypeGenerator is NullCSharpEntityTypeGenerator))
Expand All @@ -163,11 +159,7 @@ public virtual ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationOp
entityTypeFileName = entityType.GetSchema() + @"\" + entityTypeFileName;
}
resultingFiles.AdditionalFiles.Add(
new ScaffoldedFile
{
Path = entityTypeFileName,
Code = generatedCode
});
new ScaffoldedFile(entityTypeFileName, generatedCode));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit d4f974c

Please sign in to comment.