Skip to content

Commit

Permalink
add new option (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaceWindu authored Jun 9, 2023
1 parent a4f13c3 commit 0f9e695
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Build/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
14 changes: 7 additions & 7 deletions Build/linq2db.LINQPad.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
<readme>README.md</readme>
<dependencies>
<group targetFramework="net6.0">
<dependency id="linq2db" version="5.1.1" />
<dependency id="linq2db.Tools" version="5.1.1" />
<dependency id="linq2db" version="5.2.2" />
<dependency id="linq2db.Tools" version="5.2.2" />

<dependency id="LINQPad.Reference" version="1.3.0" />

<dependency id="System.Configuration.ConfigurationManager" version="7.0.0" />
<dependency id="Microsoft.CodeAnalysis.CSharp" version="4.5.0" />
<dependency id="Microsoft.CodeAnalysis.CSharp" version="4.6.0" />
<dependency id="System.Text.Json" version="7.0.2" />

<dependency id="FirebirdSql.Data.FirebirdClient" version="9.1.1" />
<dependency id="MySqlConnector" version="2.2.5" />
<dependency id="MySqlConnector" version="2.2.6" />
<dependency id="AdoNetCore.AseClient" version="0.19.2" />
<dependency id="System.Data.SQLite.Core" version="1.0.117" />
<dependency id="Microsoft.Data.SqlClient" version="5.1.1" />
<dependency id="Microsoft.SqlServer.Types" version="160.1000.6" />
<dependency id="System.Data.Odbc" version="7.0.0" />
<dependency id="System.Data.OleDb" version="7.0.0" />
<dependency id="Npgsql" version="7.0.2" />
<dependency id="Npgsql" version="7.0.4" />
<dependency id="Oracle.ManagedDataAccess.Core" version="3.21.100" />
<dependency id="Net.IBM.Data.Db2" version="6.0.0.300" />
<dependency id="ClickHouse.Client" version="6.5.2" />
<dependency id="Net.IBM.Data.Db2" version="7.0.0.200" />
<dependency id="ClickHouse.Client" version="6.6.0" />
<dependency id="Octonica.ClickHouseClient" version="2.2.9" />
<!--<dependency id="linq2db4iSeries" version="4.3.0" />-->
</group>
Expand Down
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project>
<ItemGroup>
<PackageVersion Include="linq2db" Version="5.1.1" />
<PackageVersion Include="linq2db.Tools" Version="5.1.1" />
<PackageVersion Include="linq2db" Version="5.2.2" />
<PackageVersion Include="linq2db.Tools" Version="5.2.2" />

<PackageVersion Include="LINQPad.Reference" Version="1.3.0" />

<PackageVersion Include="PolySharp" Version="1.13.1" />
<PackageVersion Include="PolySharp" Version="1.13.2" />

<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
Expand All @@ -19,16 +19,16 @@
<PackageVersion Include="System.Data.SQLite.Core" Version="1.0.117" />
<PackageVersion Include="System.Data.Odbc" Version="7.0.0" />
<PackageVersion Include="System.Data.OleDb" Version="7.0.0" />
<PackageVersion Include="MySqlConnector" Version="2.2.5" />
<PackageVersion Include="MySqlConnector" Version="2.2.6" />
<PackageVersion Include="AdoNetCore.AseClient" Version="0.19.2" />
<PackageVersion Include="IBM.Data.DB.Provider" Version="11.5.5010.4" GeneratePathProperty="true" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageVersion Include="Oracle.ManagedDataAccess" Version="21.10.0" />
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="3.21.100" />
<PackageVersion Include="Net.IBM.Data.Db2" Version="6.0.0.300" />
<PackageVersion Include="ClickHouse.Client" Version="6.5.2" />
<PackageVersion Include="Net.IBM.Data.Db2" Version="7.0.0.200" />
<PackageVersion Include="ClickHouse.Client" Version="6.6.0" />
<PackageVersion Include="FirebirdSql.Data.FirebirdClient" Version="9.1.1" />
<PackageVersion Include="Npgsql" Version="7.0.2" />
<PackageVersion Include="Npgsql" Version="7.0.4" />
<PackageVersion Include="Octonica.ClickHouseClient" Version="2.2.9" />
<!--<PackageVersion Include="linq2db4iSeries" Version="5.1.0" />-->

Expand Down
12 changes: 12 additions & 0 deletions Source/Configuration/ConnectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?)
Expand Down Expand Up @@ -490,6 +496,12 @@ public sealed class ScaffoldOptions
/// </summary>
[JsonIgnore]
public bool Capitalize { get; set; }

/// <summary>
/// When set, default database object name normalization rules disabled (except modification set
/// by <see cref="Pluralize"/> and <see cref="Capitalize"/> options).
/// </summary>
public bool AsIsNames { get; set; }
}

public sealed class LinqToDbOptions
Expand Down
35 changes: 35 additions & 0 deletions Source/Drivers/DynamicSchemaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions Source/UI/Model/ScaffoldModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions Source/UI/Settings/ScaffoldTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

<GroupBox Header="Scaffold Options">
<StackPanel Margin="5">
<CheckBox
Margin="5"
IsChecked="{Binding AsIsNames}"
Content="Use table/column names as-is"
ToolTip="When option is not set table, view and column names converted to PascalCase" />

<CheckBox
Margin="5"
IsChecked="{Binding Capitalize}"
Expand Down
2 changes: 1 addition & 1 deletion Source/linq2db.LINQPad.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Company>linq2db</Company>
<Product>linq2db.LINQPad</Product>
<AssemblyTitle>$(Product)</AssemblyTitle>
<Version>5.0.0.0</Version>
<Version>5.1.0.0</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Copyright>Copyright © 2016-2023 Linq To DB Team</Copyright>
Expand Down
6 changes: 6 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 0f9e695

Please sign in to comment.