From 0f9e695c93dd06e36ab0c7c34514c66032d32dd5 Mon Sep 17 00:00:00 2001 From: MaceWindu Date: Fri, 9 Jun 2023 21:09:41 +0200 Subject: [PATCH] add new option (#91) --- Build/azure-pipelines.yml | 8 ++--- Build/linq2db.LINQPad.nuspec | 14 ++++----- Directory.Packages.props | 16 +++++----- Source/Configuration/ConnectionSettings.cs | 12 ++++++++ Source/Drivers/DynamicSchemaGenerator.cs | 35 ++++++++++++++++++++++ Source/UI/Model/ScaffoldModel.cs | 6 ++++ Source/UI/Settings/ScaffoldTab.xaml | 6 ++++ Source/linq2db.LINQPad.csproj | 2 +- release-notes.md | 6 ++++ 9 files changed, 85 insertions(+), 20 deletions(-) diff --git a/Build/azure-pipelines.yml b/Build/azure-pipelines.yml index 7f0146d..319b16f 100644 --- a/Build/azure-pipelines.yml +++ b/Build/azure-pipelines.yml @@ -1,10 +1,10 @@ variables: solution: 'linq2db.LINQPad.sln' build_configuration: 'Release' - assemblyVersion: 5.0.0.0 - nugetVersion: 5.0.0 - nugetDevVersion: 5.0.1 - nugetPRVersion: 5.0.1 + assemblyVersion: 5.1.0.0 + nugetVersion: 5.1.0 + nugetDevVersion: 5.1.1 + nugetPRVersion: 5.1.1 artifact_lpx: 'lpx' artifact_lpx6: 'lpx6' artifact_nuget: 'nuget' diff --git a/Build/linq2db.LINQPad.nuspec b/Build/linq2db.LINQPad.nuspec index 9395765..534ccd4 100644 --- a/Build/linq2db.LINQPad.nuspec +++ b/Build/linq2db.LINQPad.nuspec @@ -11,27 +11,27 @@ README.md - - + + - + - + - + - - + + diff --git a/Directory.Packages.props b/Directory.Packages.props index 58366b1..cc6ba28 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,13 +1,13 @@  - - + + - + - + @@ -19,16 +19,16 @@ - + - - + + - + diff --git a/Source/Configuration/ConnectionSettings.cs b/Source/Configuration/ConnectionSettings.cs index 806f08d..c369470 100644 --- a/Source/Configuration/ConnectionSettings.cs +++ b/Source/Configuration/ConnectionSettings.cs @@ -166,6 +166,9 @@ public static ConnectionSettings Load(IConnectionInfo cxInfo) // old provider name option replaced with two options: database and database provider settings.Connection.Provider = GetString(cxInfo, ProviderName); + // used to distinguish new connection dialog from migration + var isNew = settings.Connection.Provider == null; + // this native oracle provider was removed long time ago and not supported in v5 too if (settings.Connection.Provider == PN.OracleNative) settings.Connection.Provider = PN.OracleManaged; @@ -257,6 +260,9 @@ or PN.SqlServer // 10. CustomConfiguration migration settings.StaticContext.ConfigurationName = GetString(cxInfo, CustomConfiguration); + // https://github.com/linq2db/linq2db.LINQPad/issues/89 + settings.Scaffold.AsIsNames = !isNew; + // ignored options: // UseCustomFormatter - removed in v5 // NormalizeNames - not used in pre-v5 and v5 (never used?) @@ -490,6 +496,12 @@ public sealed class ScaffoldOptions /// [JsonIgnore] public bool Capitalize { get; set; } + + /// + /// When set, default database object name normalization rules disabled (except modification set + /// by and options). + /// + public bool AsIsNames { get; set; } } public sealed class LinqToDbOptions diff --git a/Source/Drivers/DynamicSchemaGenerator.cs b/Source/Drivers/DynamicSchemaGenerator.cs index e026208..78158fb 100644 --- a/Source/Drivers/DynamicSchemaGenerator.cs +++ b/Source/Drivers/DynamicSchemaGenerator.cs @@ -42,13 +42,48 @@ private static ScaffoldOptions GetOptions(ConnectionSettings settings, string? c //options.Schema.EnableSqlServerReturnValue = true; // set data model options + if (settings.Scaffold.AsIsNames) + { + // https://github.com/linq2db/linq2db.LINQPad/issues/89 + // reset naming options for some objects: + // - entities + // - context properties + // - columns + // more could be added later on request + options.DataModel.EntityClassNameOptions.Casing = NameCasing.None; + options.DataModel.EntityClassNameOptions.Pluralization = Pluralization.None; + options.DataModel.EntityClassNameOptions.Transformation = NameTransformation.None; + options.DataModel.EntityClassNameOptions.DontCaseAllCaps = true; + options.DataModel.EntityClassNameOptions.PluralizeOnlyIfLastWordIsText = false; + + options.DataModel.EntityContextPropertyNameOptions.Casing = NameCasing.None; + options.DataModel.EntityContextPropertyNameOptions.Pluralization = Pluralization.None; + options.DataModel.EntityContextPropertyNameOptions.Transformation = NameTransformation.None; + options.DataModel.EntityContextPropertyNameOptions.DontCaseAllCaps = true; + options.DataModel.EntityContextPropertyNameOptions.PluralizeOnlyIfLastWordIsText = false; + + options.DataModel.EntityColumnPropertyNameOptions.Casing = NameCasing.None; + options.DataModel.EntityColumnPropertyNameOptions.Pluralization = Pluralization.None; + options.DataModel.EntityColumnPropertyNameOptions.Transformation = NameTransformation.None; + options.DataModel.EntityColumnPropertyNameOptions.DontCaseAllCaps = true; + options.DataModel.EntityColumnPropertyNameOptions.PluralizeOnlyIfLastWordIsText = false; + } + if (!settings.Scaffold.Capitalize) options.DataModel.EntityColumnPropertyNameOptions.Casing = NameCasing.None; + else + options.DataModel.EntityColumnPropertyNameOptions.Casing = NameCasing.Pascal; + if (!settings.Scaffold.Pluralize) { options.DataModel.EntityContextPropertyNameOptions.Pluralization = Pluralization.None; options.DataModel.TargetMultipleAssociationPropertyNameOptions.Pluralization = Pluralization.None; } + else + { + options.DataModel.EntityContextPropertyNameOptions.Pluralization = Pluralization.PluralIfLongerThanOne; + options.DataModel.TargetMultipleAssociationPropertyNameOptions.Pluralization = Pluralization.PluralIfLongerThanOne; + } options.DataModel.GenerateDefaultSchema = true; options.DataModel.GenerateDataType = true; diff --git a/Source/UI/Model/ScaffoldModel.cs b/Source/UI/Model/ScaffoldModel.cs index 095db86..ae17d66 100644 --- a/Source/UI/Model/ScaffoldModel.cs +++ b/Source/UI/Model/ScaffoldModel.cs @@ -23,6 +23,12 @@ public bool Pluralize set => Settings.Scaffold.Pluralize = value; } + public bool AsIsNames + { + get => Settings.Scaffold.AsIsNames; + set => Settings.Scaffold.AsIsNames = value; + } + public bool UseProviderTypes { get => Settings.Scaffold.UseProviderTypes; diff --git a/Source/UI/Settings/ScaffoldTab.xaml b/Source/UI/Settings/ScaffoldTab.xaml index 968893d..3b6e034 100644 --- a/Source/UI/Settings/ScaffoldTab.xaml +++ b/Source/UI/Settings/ScaffoldTab.xaml @@ -12,6 +12,12 @@ + + linq2db linq2db.LINQPad $(Product) - 5.0.0.0 + 5.1.0.0 $(Version) $(Version) Copyright © 2016-2023 Linq To DB Team diff --git a/release-notes.md b/release-notes.md index db761f5..a4aeae4 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,9 @@ +# Release 5.1.0 + +Issues fixed: + +- [#89](https://github.com/linq2db/linq2db.LINQPad/pull/89), [#90](https://github.com/linq2db/linq2db.LINQPad/pull/90): add scaffold option to use database object names as-is + # Release 5.0.0 Complete driver rewrite: