From 20bdbb6d75e933332dea76330ac75b39fba1a461 Mon Sep 17 00:00:00 2001 From: Alexanderius Date: Sun, 14 Jan 2024 11:11:06 +0600 Subject: [PATCH] [#487] [add] MS SQL dialect [#487] [edit] version/changelog --- src/Simplify.FluentNHibernate/CHANGELOG.md | 14 ++++++++ .../ConfigurationExtensions.cs | 32 +++++++++++++------ .../Dialects/MsSqlDialect.cs | 28 ++++++++++++++++ .../Simplify.FluentNHibernate.csproj | 2 +- 4 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 src/Simplify.FluentNHibernate/Dialects/MsSqlDialect.cs diff --git a/src/Simplify.FluentNHibernate/CHANGELOG.md b/src/Simplify.FluentNHibernate/CHANGELOG.md index 382f0ff8..711159a1 100644 --- a/src/Simplify.FluentNHibernate/CHANGELOG.md +++ b/src/Simplify.FluentNHibernate/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [3.0.0] - 2024-01-14 + +### Added + +- InitializeFromConfig* methods selectable dialect (#487) +- CompositeInterceptor (#483) + +### Changed + +- Default PostgreSQL83 dialect set for PostgreSQL connections +- Default MsSql2012 dialect set for MS SQL connections +- InitializeFromConfigMsSql null password exception +- SessionFactoryBuilderBase dispose with GC.SuppressFinalize + ## [2.6.0] - 2023-08-07 ### Removed diff --git a/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs b/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs index 96ee7707..6c20ad15 100644 --- a/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs +++ b/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs @@ -372,17 +372,19 @@ private static void InitializeFromConfigMySql(FluentConfiguration fluentConfigur /// The fluentNHibernate configuration. /// Configuration section name in App.config or Web.config file. /// The additional client configuration. - /// + /// The dialect. /// fluentConfiguration public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfiguration fluentConfiguration, string configSectionName = "DatabaseConnectionSettings", - Action? additionalClientConfiguration = null) + Action? additionalClientConfiguration = null, + MsSqlDialect dialect = MsSqlDialect.MsSql2012) { if (fluentConfiguration == null) throw new ArgumentNullException(nameof(fluentConfiguration)); InitializeFromConfigMsSql(fluentConfiguration, new ConfigurationManagerBasedDbConnectionSettings(configSectionName), - additionalClientConfiguration); + additionalClientConfiguration, + dialect); return fluentConfiguration; } @@ -394,7 +396,7 @@ public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfigura /// The configuration containing database config section. /// Database configuration section name in configuration. /// The additional client configuration. - /// + /// The dialect. /// /// fluentConfiguration /// or @@ -403,27 +405,39 @@ public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfigura public static FluentConfiguration InitializeFromConfigMsSql(this FluentConfiguration fluentConfiguration, IConfiguration configuration, string configSectionName = "DatabaseConnectionSettings", - Action? additionalClientConfiguration = null) + Action? additionalClientConfiguration = null, + MsSqlDialect dialect = MsSqlDialect.MsSql2012) { if (fluentConfiguration == null) throw new ArgumentNullException(nameof(fluentConfiguration)); if (configuration == null) throw new ArgumentNullException(nameof(configuration)); InitializeFromConfigMsSql(fluentConfiguration, new ConfigurationBasedDbConnectionSettings(configuration, configSectionName), - additionalClientConfiguration); + additionalClientConfiguration, + dialect); return fluentConfiguration; } private static void InitializeFromConfigMsSql(FluentConfiguration fluentConfiguration, DbConnectionSettings settings, - Action? additionalClientConfiguration = null) + Action? additionalClientConfiguration = null, + MsSqlDialect dialect = MsSqlDialect.MsSql2012) { - var clientConfiguration = MsSqlConfiguration.MsSql2008.ConnectionString(c => c + var clientConfiguration = dialect switch + { + MsSqlDialect.MsSql2000 => MsSqlConfiguration.MsSql2000, + MsSqlDialect.MsSql2005 => MsSqlConfiguration.MsSql2005, + MsSqlDialect.MsSql2008 => MsSqlConfiguration.MsSql2008, + MsSqlDialect.MsSql7 => MsSqlConfiguration.MsSql7, + _ => throw new InvalidOperationException() + }; + + clientConfiguration.ConnectionString(c => c .Server(settings.ServerName) .Database(settings.DataBaseName) .Username(settings.UserName) - .Password(settings.UserPassword ?? throw new ArgumentNullException(nameof(settings.UserPassword)))); + .Password(settings.UserPassword ?? throw new ArgumentException($"{nameof(settings.UserPassword)} is null"))); additionalClientConfiguration?.Invoke(clientConfiguration); diff --git a/src/Simplify.FluentNHibernate/Dialects/MsSqlDialect.cs b/src/Simplify.FluentNHibernate/Dialects/MsSqlDialect.cs new file mode 100644 index 00000000..9fcc22d0 --- /dev/null +++ b/src/Simplify.FluentNHibernate/Dialects/MsSqlDialect.cs @@ -0,0 +1,28 @@ +namespace Simplify.FluentNHibernate.Dialects; + +/// +/// Provides MS SQL DBMS dialect +/// +public enum MsSqlDialect +{ + /// + /// The MS SQL 2000 dialect + /// + MsSql2000, + /// + /// The MS SQL 2005 dialect + /// + MsSql2005, + /// + /// The MS SQL 2008 dialect + /// + MsSql2008, + /// + /// The MS SQL 2012 dialect + /// + MsSql2012, + /// + /// The MS SQL 7 dialect + /// + MsSql7 +} \ No newline at end of file diff --git a/src/Simplify.FluentNHibernate/Simplify.FluentNHibernate.csproj b/src/Simplify.FluentNHibernate/Simplify.FluentNHibernate.csproj index c5dfe0b9..acc64145 100644 --- a/src/Simplify.FluentNHibernate/Simplify.FluentNHibernate.csproj +++ b/src/Simplify.FluentNHibernate/Simplify.FluentNHibernate.csproj @@ -8,7 +8,7 @@ snupkg true - 2.6 + 3.0 Alexander Krylkov Simplify