Skip to content

Commit

Permalink
EF Core 8 reverse engineer support (#1907)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ authored Jul 31, 2023
1 parent 22a0f67 commit cc1640d
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 54 deletions.
30 changes: 30 additions & 0 deletions src/GUI/EFCorePowerTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ErikEJ.EntityFrameworkCore.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DacFxStrongTypedCore.161", "DacFxStrongTypedCore.161\DacFxStrongTypedCore.161.csproj", "{F5032B12-DBC7-4B98-8324-C357A2C8CCE2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevEng.Core.80", "RevEng.Core.80\RevEng.Core.80.csproj", "{DFA5B4A2-0771-436E-B111-4CE3821D2697}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "efreveng80", "efreveng80\efreveng80.csproj", "{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -352,6 +356,30 @@ Global
{F5032B12-DBC7-4B98-8324-C357A2C8CCE2}.Release|arm64.Build.0 = Release|Any CPU
{F5032B12-DBC7-4B98-8324-C357A2C8CCE2}.Release|x86.ActiveCfg = Release|Any CPU
{F5032B12-DBC7-4B98-8324-C357A2C8CCE2}.Release|x86.Build.0 = Release|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Debug|arm64.ActiveCfg = Debug|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Debug|arm64.Build.0 = Debug|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Debug|x86.ActiveCfg = Debug|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Debug|x86.Build.0 = Debug|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Release|Any CPU.Build.0 = Release|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Release|arm64.ActiveCfg = Release|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Release|arm64.Build.0 = Release|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Release|x86.ActiveCfg = Release|Any CPU
{DFA5B4A2-0771-436E-B111-4CE3821D2697}.Release|x86.Build.0 = Release|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Debug|arm64.ActiveCfg = Debug|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Debug|arm64.Build.0 = Debug|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Debug|x86.ActiveCfg = Debug|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Debug|x86.Build.0 = Debug|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Release|Any CPU.Build.0 = Release|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Release|arm64.ActiveCfg = Release|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Release|arm64.Build.0 = Release|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Release|x86.ActiveCfg = Release|Any CPU
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -377,6 +405,8 @@ Global
{64EF1EE1-CA06-4218-80A1-E33931119DDF} = {F33E4994-452C-4C09-9FB5-C2E17D0884B6}
{198C02B0-2665-4151-A051-D685CA0D09E8} = {8B7992B9-F570-4E74-8AE4-F9436BD7CBEF}
{F5032B12-DBC7-4B98-8324-C357A2C8CCE2} = {F33E4994-452C-4C09-9FB5-C2E17D0884B6}
{DFA5B4A2-0771-436E-B111-4CE3821D2697} = {F33E4994-452C-4C09-9FB5-C2E17D0884B6}
{50EA6A90-2AF3-4A5D-A374-B83BEBDBF7C2} = {F33E4994-452C-4C09-9FB5-C2E17D0884B6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BFF7B9CC-46C9-4547-9FA1-D17E2A89613C}
Expand Down
4 changes: 4 additions & 0 deletions src/GUI/EFCorePowerTools/EFCorePowerTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@
<Link>efpt70sc.exe.zip</Link>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="..\lib\efreveng80.exe.zip">
<Link>efreveng80.exe.zip</Link>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="app.config" />
<Content Include="CodeTemplates600.zip">
<IncludeInVSIX>true</IncludeInVSIX>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ColumnRemovingScaffoldingModelFactory : RelationalScaffoldingModelF
private readonly DatabaseType databaseType;
private readonly bool ignoreManyToMany;

#if !CORE70
#if !CORE70 && !CORE80
public ColumnRemovingScaffoldingModelFactory([NotNull] IOperationReporter reporter, [NotNull] ICandidateNamingService candidateNamingService, [NotNull] IPluralizer pluralizer, [NotNull] ICSharpUtilities cSharpUtilities, [NotNull] IScaffoldingTypeMapper scaffoldingTypeMapper, [NotNull] LoggingDefinitions loggingDefinitions, [NotNull] IModelRuntimeInitializer modelRuntimeInitializer, List<SerializationTableModel> tables, DatabaseType databaseType, bool ignoreManyToMany)
: base(reporter, candidateNamingService, pluralizer, cSharpUtilities, scaffoldingTypeMapper, loggingDefinitions, modelRuntimeInitializer)
#else
Expand Down
9 changes: 7 additions & 2 deletions src/GUI/RevEng.Core.60/ConnectionStringResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
using System.Collections.Generic;
using System.Data.Common;
using System.IO;
using FirebirdSql.Data.FirebirdClient;
using Microsoft.Data.SqlClient;
using Microsoft.Data.Sqlite;
using Npgsql;

#if !CORE80
using FirebirdSql.Data.FirebirdClient;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using MySqlConnector;
using Npgsql;
using Oracle.ManagedDataAccess.Client;
#endif

namespace RevEng.Core
{
Expand Down Expand Up @@ -65,6 +68,7 @@ public IList<string> ResolveAlias()
// Ignore
}

#if !CORE80
try
{
var a = new MySqlConnectionStringBuilder(connectionString);
Expand Down Expand Up @@ -94,6 +98,7 @@ public IList<string> ResolveAlias()
{
// Ignore
}
#endif

return aliases;
}
Expand Down
8 changes: 4 additions & 4 deletions src/GUI/RevEng.Core.60/ReverseEngineerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static ReverseEngineerResult GenerateFiles(ReverseEngineerCommandOptions
{
SavedModelFiles filePaths = scaffolder!.GenerateDbContext(options, schemas, outputContextDir, modelNamespace, contextNamespace, options.ProjectPath, options.OutputPath);

#if CORE70
#if CORE70 || CORE80
if (options.UseT4)
{
foreach (var paths in GetAlternateCodeTemplatePaths(options.ProjectPath))
Expand All @@ -113,7 +113,7 @@ public static ReverseEngineerResult GenerateFiles(ReverseEngineerCommandOptions
var index = dbContextLines.FindIndex(l => l.Contains(" OnModelCreatingPartial(modelBuilder);", StringComparison.Ordinal));
if (index != -1)
{
#if CORE70
#if CORE70 || CORE80
dbContextLines.Insert(index, " OnModelCreatingGeneratedProcedures(modelBuilder);");
#else
dbContextLines.Insert(index, " OnModelCreatingGeneratedProcedures(modelBuilder);");
Expand All @@ -126,7 +126,7 @@ public static ReverseEngineerResult GenerateFiles(ReverseEngineerCommandOptions
var index = dbContextLines.FindIndex(l => l.Contains(" OnModelCreatingPartial(modelBuilder);", StringComparison.Ordinal));
if (index != -1)
{
#if CORE70
#if CORE70 || CORE80
dbContextLines.Insert(index, " OnModelCreatingGeneratedFunctions(modelBuilder);");
#else
dbContextLines.Insert(index, " OnModelCreatingGeneratedFunctions(modelBuilder);");
Expand Down Expand Up @@ -246,7 +246,7 @@ public static void RetryFileWrite(string path, string finalText)
}
}

#if CORE70
#if CORE70 || CORE80
private static List<(string Path, string OutputPath)> GetAlternateCodeTemplatePaths(string projectPath)
{
var result = new List<(string Path, string OutputPath)>();
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/RevEng.Core.60/ReverseEngineerScaffolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public SavedModelFiles GenerateDbContext(
ConnectionString = options.ConnectionString,
SuppressOnConfiguring = !options.IncludeConnectionString,
UseNullableReferenceTypes = options.UseNullableReferences,
#if CORE70
#if CORE70 || CORE80
ProjectDir = options.UseT4 ? (options.T4TemplatePath ?? projectPath) : null,
#endif
};
Expand Down Expand Up @@ -486,7 +486,7 @@ private ScaffoldedModel ScaffoldModel(
{
throw new InvalidOperationException($"No model from provider {factory.GetType().ShortDisplayName()}");
}
#if CORE70
#if CORE70 || CORE80
var codeGenerator = ModelCodeGeneratorSelector.Select(codeOptions);
#else
var codeGenerator = ModelCodeGeneratorSelector.Select(codeOptions.Language);
Expand Down
48 changes: 36 additions & 12 deletions src/GUI/RevEng.Core.60/ServiceProviderBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
using System;
using System.Collections.Generic;
using EntityFrameworkCore.Scaffolding.Handlebars;
using System.Linq;
using ErikEJ.EntityFrameworkCore.SqlServer.Scaffolding;
using FirebirdSql.EntityFrameworkCore.Firebird.Design.Internal;
using Humanizer.Inflections;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
using Microsoft.EntityFrameworkCore.Sqlite.Design.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Design;
using Microsoft.EntityFrameworkCore.SqlServer.Design.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal;
using Oracle.EntityFrameworkCore.Design.Internal;
using Pomelo.EntityFrameworkCore.MySql.Design.Internal;
using RevEng.Common;
using RevEng.Core.Procedures;

#if !CORE80
using EntityFrameworkCore.Scaffolding.Handlebars;
using FirebirdSql.EntityFrameworkCore.Firebird.Design.Internal;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore.SqlServer.Design;
using Oracle.EntityFrameworkCore.Design.Internal;
using Pomelo.EntityFrameworkCore.MySql.Design.Internal;
using SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime.Design;
#endif

namespace RevEng.Core
{
Expand All @@ -33,6 +39,11 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
throw new ArgumentNullException(nameof(options));
}

if (serviceCollection == null)
{
throw new ArgumentNullException(nameof(serviceCollection));
}

var reporter = new OperationReporter(
new OperationReportHandler(
m => errors.Add(m),
Expand Down Expand Up @@ -62,6 +73,7 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
serviceCollection.AddSingleton<ICandidateNamingService>(provider => new ReplacingCandidateNamingService(options.CustomReplacers, options.PreserveCasingWithRegex));
}

#if !CORE80
if (options.UseHandleBars)
{
serviceCollection.AddHandlebarsScaffolding(hbOptions =>
Expand All @@ -72,7 +84,7 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
serviceCollection.AddSingleton<ITemplateFileService>(provider
=> new CustomTemplateFileService(options.OptionsPath));
}

#endif
if (options.UseInflector || options.UseLegacyPluralizer)
{
if (options.UseLegacyPluralizer)
Expand All @@ -99,7 +111,16 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
var provider = new SqlServerDesignTimeServices();
provider.ConfigureDesignTimeServices(serviceCollection);

#if !CORE80
serviceCollection.AddSingleton<IDatabaseModelFactory, PatchedSqlServerDatabaseModelFactory>();
#else
serviceCollection.AddSingleton<IRelationalTypeMappingSource, SqlServerTypeMappingSource>(
provider => new RevEng.Core.SqlServerTypeMappingSource(
provider.GetService<TypeMappingSourceDependencies>(),
provider.GetService<RelationalTypeMappingSourceDependencies>(),
provider.GetService<ISqlServerSingletonOptions>(),
options.UseDateOnlyTimeOnly));
#endif

serviceCollection.AddSqlServerStoredProcedureDesignTimeServices();
serviceCollection.AddSqlServerFunctionDesignTimeServices();
Expand All @@ -116,6 +137,7 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
hierachyId.ConfigureDesignTimeServices(serviceCollection);
}

#if !CORE80
if (options.UseNodaTime)
{
var nodaTime = new SqlServerNodaTimeDesignTimeServices();
Expand All @@ -127,7 +149,7 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
var dateOnlyTimeOnly = new SqlServerDateOnlyTimeOnlyDesignTimeServices();
dateOnlyTimeOnly.ConfigureDesignTimeServices(serviceCollection);
}

#endif
break;

case DatabaseType.SQLServerDacpac:
Expand Down Expand Up @@ -156,7 +178,7 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
var hierachyId = new SqlServerHierarchyIdDesignTimeServices();
hierachyId.ConfigureDesignTimeServices(serviceCollection);
}

#if !CORE80
if (options.UseNodaTime)
{
var nodaTime = new SqlServerNodaTimeDesignTimeServices();
Expand All @@ -168,7 +190,7 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
var dateOnlyTimeOnly = new SqlServerDateOnlyTimeOnlyDesignTimeServices();
dateOnlyTimeOnly.ConfigureDesignTimeServices(serviceCollection);
}

#endif
break;

case DatabaseType.Npgsql:
Expand All @@ -189,6 +211,7 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti

break;

#if !CORE80
case DatabaseType.Mysql:
var mysqlProvider = new MySqlDesignTimeServices();
mysqlProvider.ConfigureDesignTimeServices(serviceCollection);
Expand All @@ -210,17 +233,18 @@ public static IServiceCollection AddEfpt(this IServiceCollection serviceCollecti
var firebirdProvider = new FbDesignTimeServices();
firebirdProvider.ConfigureDesignTimeServices(serviceCollection);
break;

#endif
case DatabaseType.SQLite:
var sqliteProvider = new SqliteDesignTimeServices();
sqliteProvider.ConfigureDesignTimeServices(serviceCollection);

#if !CORE80
if (options.UseNodaTime)
{
var nodaTime = new SqliteNodaTimeDesignTimeServices();
nodaTime.ConfigureDesignTimeServices(serviceCollection);
}

#endif
break;

default:
Expand Down
2 changes: 2 additions & 0 deletions src/GUI/RevEng.Core.60/SkuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ compatibility_level As CompatibilityLevel
#pragma warning restore CA2100 // Review SQL queries for security vulnerabilities
}
}
#pragma warning disable CA1031 // Do not catch general exception types
catch
{
// Ignore
}
#pragma warning restore CA1031 // Do not catch general exception types

break;
case DatabaseType.SQLite:
Expand Down
57 changes: 57 additions & 0 deletions src/GUI/RevEng.Core.80/RevEng.Core.80.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>$(NoWarn);EF1001</NoWarn>
<RootNamespace>RevEng.Core</RootNamespace>
<Nullable>warnings</Nullable>
</PropertyGroup>

<PropertyGroup>
<DefineConstants>TRACE;CORE60;CORE80</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\RevEng.Core.60\*.cs" Link="%(Filename)%(Extension)" />
<Compile Include="..\RevEng.Core.60\Functions\*.cs" Link="Functions\%(Filename)%(Extension)" />
<Compile Include="..\RevEng.Core.60\Routines\*.cs" Link="Routines\%(Filename)%(Extension)" />
<Compile Include="..\RevEng.Core.60\Procedures\*.cs" Link="Procedures\%(Filename)%(Extension)" />
<Compile Include="..\RevEng.Core.60\Dgml\*.cs" Link="Dgml\%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<Compile Remove="..\RevEng.Core.60\CrmDatabaseModelFactory.cs" />
<Compile Remove="..\RevEng.Core.60\CustomTemplateFileService.cs" />
<Compile Remove="..\RevEng.Core.60\PatchedSqlServerDatabaseModelFactory.cs" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\RevEng.Core.60\DbContextExtensions" Link="DbContextExtensions" />
<EmbeddedResource Include="..\RevEng.Core.60\DbContextExtensions.Sync" Link="DbContextExtensions.Sync" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Bricelam.EntityFrameworkCore.Pluralizer" Version="1.0.0" />
<!--<PackageReference Include="EntityFrameworkCore.Scaffolding.Handlebars" Version="7.0.0" />-->
<!--<PackageReference Include="EntityFrameworkCore.Sqlite.NodaTime" Version="7.0.0" />-->
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.HierarchyId" Version="8.0.0-preview.6.23329.4" />
<!--<PackageReference Include="FirebirdSql.EntityFrameworkCore.Firebird" Version="9.2.0-alpha1" />-->
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0-preview.6.23329.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-preview.6.23329.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="8.0.0-preview.6.23329.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="8.0.0-preview.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="8.0.0-preview.4" />
<!--<PackageReference Include="Oracle.EntityFrameworkCore" Version="7.21.9" />-->
<!--<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.NetTopologySuite" Version="7.0.0" />-->
<!--<PackageReference Include="SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime" Version="7.0.0" />-->
<PackageReference Include="System.CodeDom" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ErikEJ.EntityFrameworkCore.7.SqlServer.Dacpac\ErikEJ.EntityFrameworkCore.7.SqlServer.Dacpac.csproj" />
<ProjectReference Include="..\RevEng.Core.Abstractions\RevEng.Core.Abstractions.csproj" />
<ProjectReference Include="..\RevEng.Shared\RevEng.Common.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit cc1640d

Please sign in to comment.