From 538e311d5a617ae84d9c2c4fcd9f0579392c1fd8 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 17:26:55 +0200 Subject: [PATCH 01/19] fix the project path --- Dapper.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dapper.sln b/Dapper.sln index e993c7a4..4aa75f10 100644 --- a/Dapper.sln +++ b/Dapper.sln @@ -16,7 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution version.json = version.json EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper.Contrib", "Dapper.Contrib\Dapper.Contrib.csproj", "{4E409F8F-CFBB-4332-8B0A-FD5A283051FD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper.Contrib", "src\Dapper.Contrib\Dapper.Contrib.csproj", "{4E409F8F-CFBB-4332-8B0A-FD5A283051FD}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper.Tests.Contrib", "tests\Dapper.Tests.Contrib\Dapper.Tests.Contrib.csproj", "{DAB3C5B7-BCD1-4A5F-BB6B-50D2BB63DB4A}" EndProject From d36a1dcf40aa078534742dce8d3ce1396dead5ad Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 17:38:00 +0200 Subject: [PATCH 02/19] Add schema name --- src/Dapper.Contrib/Dapper.Contrib.csproj | 4 ++-- src/Dapper.Contrib/SqlMapperExtensions.cs | 12 +++++++++++- .../Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj | 8 ++++---- tests/Dapper.Tests.Contrib/TestSuites.cs | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Dapper.Contrib/Dapper.Contrib.csproj b/src/Dapper.Contrib/Dapper.Contrib.csproj index 86a0cbb2..ad614c6e 100644 --- a/src/Dapper.Contrib/Dapper.Contrib.csproj +++ b/src/Dapper.Contrib/Dapper.Contrib.csproj @@ -5,12 +5,12 @@ orm;sql;micro-orm;dapper The official collection of get, insert, update and delete helpers for Dapper.net. Also handles lists of entities and optional "dirty" tracking of interface-based entities. Sam Saffron;Johan Danforth - net461;netstandard2.0;net5.0 + net6.0;net7.0;net8.0 false $(NoWarn);CA1050 - + diff --git a/src/Dapper.Contrib/SqlMapperExtensions.cs b/src/Dapper.Contrib/SqlMapperExtensions.cs index 9a30e805..787d107f 100644 --- a/src/Dapper.Contrib/SqlMapperExtensions.cs +++ b/src/Dapper.Contrib/SqlMapperExtensions.cs @@ -291,6 +291,13 @@ private static string GetTableName(Type type) var tableAttrName = type.GetCustomAttribute(false)?.Name ?? (type.GetCustomAttributes(false).FirstOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic)?.Name; + + var schemaAttrr = type.GetCustomAttribute(false)?.Schema; + + if (!string.IsNullOrEmpty(schemaAttrr)) + { + tableAttrName = $"{schemaAttrr}.{tableAttrName}"; + } if (tableAttrName != null) { @@ -710,15 +717,18 @@ public class TableAttribute : Attribute /// Creates a table mapping to a specific name for Dapper.Contrib commands /// /// The name of this table in the database. - public TableAttribute(string tableName) + /// The schema name of this table in the database + public TableAttribute(string tableName, string schema = "") { Name = tableName; + Schema = schema; } /// /// The name of the table in the database /// public string Name { get; set; } + public string Schema { get; set; } } /// diff --git a/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj b/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj index d217f0ce..555e8a01 100644 --- a/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj +++ b/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj @@ -2,7 +2,7 @@ Dapper.Tests.Contrib Dapper Contrib Test Suite - netcoreapp3.1;net462;net5.0 + net6.0;net7.0;net8.0 $(NoWarn);CA1816;IDE0063;xUnit1004 @@ -13,9 +13,9 @@ - - - + + + diff --git a/tests/Dapper.Tests.Contrib/TestSuites.cs b/tests/Dapper.Tests.Contrib/TestSuites.cs index 55d4ef5c..5a23d629 100644 --- a/tests/Dapper.Tests.Contrib/TestSuites.cs +++ b/tests/Dapper.Tests.Contrib/TestSuites.cs @@ -1,8 +1,8 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.SqlClient; +using Microsoft.Data.Sqlite; using MySqlConnector; using System; using System.Data; -using System.Data.SqlClient; using System.IO; using Xunit; using Xunit.Sdk; From a749eaa2cd3ddf7279c9a7121e9a3a07c64541b6 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 17:51:20 +0200 Subject: [PATCH 03/19] update test suite --- appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d91b9d19..468fb844 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -image: Visual Studio 2019 +image: Visual Studio 2022 skip_branch_with_pr: true skip_tags: true @@ -9,7 +9,7 @@ skip_commits: environment: Appveyor: true # Postgres - POSTGRES_PATH: C:\Program Files\PostgreSQL\9.6 + POSTGRES_PATH: C:\Program Files\PostgreSQL\13 PGUSER: postgres PGPASSWORD: Password12! POSTGRES_ENV_POSTGRES_USER: postgres @@ -29,7 +29,7 @@ environment: services: - mysql - - postgresql + - postgresql13 init: - git config --global core.autocrlf input From f6320762c87664d25a0e1df1e603f6d8032057a2 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 17:56:21 +0200 Subject: [PATCH 04/19] update MySql --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 468fb844..2f5f088d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ environment: POSTGRES_ENV_POSTGRES_PASSWORD: Password12! POSTGRES_ENV_POSTGRES_DB: test # MySQL - MYSQL_PATH: C:\Program Files\MySql\MySQL Server 5.7 + MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 8.0 MYSQL_PWD: Password12! MYSQL_ENV_MYSQL_USER: root MYSQL_ENV_MYSQL_PASSWORD: Password12! From a2779839ba45cdea7f72b1e269266bb387fc91a8 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 18:01:15 +0200 Subject: [PATCH 05/19] align with mysql8 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 2f5f088d..b1aad0ad 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ environment: POSTGRES_ENV_POSTGRES_PASSWORD: Password12! POSTGRES_ENV_POSTGRES_DB: test # MySQL - MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 8.0 + MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 8 MYSQL_PWD: Password12! MYSQL_ENV_MYSQL_USER: root MYSQL_ENV_MYSQL_PASSWORD: Password12! From 6f02418d863d33c9f3bf7ff58d3191287280de37 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 18:02:52 +0200 Subject: [PATCH 06/19] bump --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index b1aad0ad..2f5f088d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ environment: POSTGRES_ENV_POSTGRES_PASSWORD: Password12! POSTGRES_ENV_POSTGRES_DB: test # MySQL - MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 8 + MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 8.0 MYSQL_PWD: Password12! MYSQL_ENV_MYSQL_USER: root MYSQL_ENV_MYSQL_PASSWORD: Password12! From a68d13340a456ffc180f63b46857f80850f59f60 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 18:07:31 +0200 Subject: [PATCH 07/19] add ps to start the mysql --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 2f5f088d..b8a49b37 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -32,9 +32,11 @@ services: - postgresql13 init: + - ps: Start-Service MySQL80 - git config --global core.autocrlf input - SET PATH=%POSTGRES_PATH%\bin;%MYSQL_PATH%\bin;%PATH% - net start MSSQL$SQL2019 + nuget: disable_publish_on_pr: true From b46ae57c9a90c78f222e489539198ef51bada5a3 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 18:08:13 +0200 Subject: [PATCH 08/19] remove the mysql service --- appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b8a49b37..cf6ea3f3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,8 +27,7 @@ environment: PostgesConnectionString: Server=localhost;Port=5432;User Id=postgres;Password=Password12!;Database=test SqlServerConnectionString: Server=(local)\SQL2019;Database=tempdb;User ID=sa;Password=Password12! -services: - - mysql +services: - postgresql13 init: From f796e129196b03bf95aeef43a28925c8edfcac62 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 18:14:09 +0200 Subject: [PATCH 09/19] update conn string for test suite and add missing xml comment --- appveyor.yml | 2 +- src/Dapper.Contrib/SqlMapperExtensions.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index cf6ea3f3..53a05626 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,7 +25,7 @@ environment: MySqlConnectionString: Server=localhost;Database=test;Uid=root;Pwd=Password12! OLEDBConnectionString: Provider=SQLOLEDB;Data Source=(local)\SQL2019;Initial Catalog=tempdb;User Id=sa;Password=Password12! PostgesConnectionString: Server=localhost;Port=5432;User Id=postgres;Password=Password12!;Database=test - SqlServerConnectionString: Server=(local)\SQL2019;Database=tempdb;User ID=sa;Password=Password12! + SqlServerConnectionString: Server=(local)\SQL2019;Database=tempdb;User ID=sa;Password=Password12!;TrustServerCertificate=True services: - postgresql13 diff --git a/src/Dapper.Contrib/SqlMapperExtensions.cs b/src/Dapper.Contrib/SqlMapperExtensions.cs index 787d107f..55a5b4b0 100644 --- a/src/Dapper.Contrib/SqlMapperExtensions.cs +++ b/src/Dapper.Contrib/SqlMapperExtensions.cs @@ -728,6 +728,10 @@ public TableAttribute(string tableName, string schema = "") /// The name of the table in the database /// public string Name { get; set; } + + /// + /// The schema of the table in the database + /// public string Schema { get; set; } } From 39964d564bf3e9794e259c0850542e441c9a0641 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 18:52:50 +0200 Subject: [PATCH 10/19] update giltab runner connstr --- .github/workflows/main.yml | 2 +- src/Dapper.Contrib/SqlMapperExtensions.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 173531df..dc54000f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,6 +48,6 @@ jobs: MySqlConnectionString: Server=localhost;Port=${{ job.services.mysql.ports[3306] }};Uid=root;Pwd=root;Database=test;Allow User Variables=true OLEDBConnectionString: Provider=SQLOLEDB;Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.; PostgesConnectionString: Server=localhost;Port=${{ job.services.postgres.ports[5432] }};Database=test;User Id=postgres;Password=postgres; - SqlServerConnectionString: Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.; + SqlServerConnectionString: Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.;TrustServerCertificate=True; - name: .NET Lib Pack run: dotnet pack Build.csproj --no-build -c Release /p:PackageOutputPath=%CD%\.nupkgs /p:CI=true diff --git a/src/Dapper.Contrib/SqlMapperExtensions.cs b/src/Dapper.Contrib/SqlMapperExtensions.cs index 55a5b4b0..c95d773a 100644 --- a/src/Dapper.Contrib/SqlMapperExtensions.cs +++ b/src/Dapper.Contrib/SqlMapperExtensions.cs @@ -6,7 +6,6 @@ using System.Text; using System.Collections.Concurrent; using System.Reflection.Emit; -using System.Threading; using Dapper; From 281c61ad31be90b96bf2167e1695a1ed3c636fe9 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 18:54:52 +0200 Subject: [PATCH 11/19] update conn string for OLEDB --- .editorconfig | 86 +++++++++++++++++++++++++++++++++++++- .github/workflows/main.yml | 2 +- Dapper.sln | 5 ++- 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index f2a67292..e7c25311 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,7 +16,7 @@ charset = utf-8-bom # Xml project files [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] -indent_size = 2 +indent_size = 4 # Xml config files [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] @@ -46,6 +46,20 @@ dotnet_style_collection_initializer = true:suggestion dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:suggestion dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +end_of_line = crlf +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion +dotnet_style_namespace_match_folder = true:suggestion # CSharp code style settings: [*.cs] @@ -77,4 +91,72 @@ csharp_new_line_before_else = true csharp_new_line_before_catch = true csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true \ No newline at end of file +csharp_new_line_before_members_in_anonymous_types = true +csharp_indent_labels = one_less_than_current +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true:silent +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion +csharp_style_prefer_tuple_swap = true:suggestion +csharp_style_prefer_utf8_string_literals = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_space_around_binary_operators = before_and_after +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc54000f..ba2aa93c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,7 +46,7 @@ jobs: run: dotnet test tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj -c Release --logger GitHubActions /p:CI=true env: MySqlConnectionString: Server=localhost;Port=${{ job.services.mysql.ports[3306] }};Uid=root;Pwd=root;Database=test;Allow User Variables=true - OLEDBConnectionString: Provider=SQLOLEDB;Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.; + OLEDBConnectionString: Provider=SQLOLEDB;Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.;TrustServerCertificate=True; PostgesConnectionString: Server=localhost;Port=${{ job.services.postgres.ports[5432] }};Database=test;User Id=postgres;Password=postgres; SqlServerConnectionString: Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.;TrustServerCertificate=True; - name: .NET Lib Pack diff --git a/Dapper.sln b/Dapper.sln index 4aa75f10..19eed964 100644 --- a/Dapper.sln +++ b/Dapper.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28917.182 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35312.102 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A34907DF-958A-4E4C-8491-84CF303FD13E}" ProjectSection(SolutionItems) = preProject @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Build.props = Directory.Build.props docs\index.md = docs\index.md License.txt = License.txt + .github\workflows\main.yml = .github\workflows\main.yml nuget.config = nuget.config Readme.md = Readme.md version.json = version.json From caca44abbb35b00407283b8d0ce16523fd9c3b32 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 19:03:26 +0200 Subject: [PATCH 12/19] restore editorconfig --- .editorconfig | 86 ++------------------------------------------------- 1 file changed, 2 insertions(+), 84 deletions(-) diff --git a/.editorconfig b/.editorconfig index e7c25311..f2a67292 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,7 +16,7 @@ charset = utf-8-bom # Xml project files [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] -indent_size = 4 +indent_size = 2 # Xml config files [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] @@ -46,20 +46,6 @@ dotnet_style_collection_initializer = true:suggestion dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:suggestion dotnet_style_explicit_tuple_names = true:suggestion -dotnet_style_operator_placement_when_wrapping = beginning_of_line -tab_width = 4 -end_of_line = crlf -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion -dotnet_style_prefer_auto_properties = true:silent -dotnet_style_prefer_simplified_boolean_expressions = true:suggestion -dotnet_style_prefer_conditional_expression_over_assignment = true:silent -dotnet_style_prefer_conditional_expression_over_return = true:silent -dotnet_style_prefer_inferred_tuple_names = true:suggestion -dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion -dotnet_style_prefer_compound_assignment = true:suggestion -dotnet_style_prefer_simplified_interpolation = true:suggestion -dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion -dotnet_style_namespace_match_folder = true:suggestion # CSharp code style settings: [*.cs] @@ -91,72 +77,4 @@ csharp_new_line_before_else = true csharp_new_line_before_catch = true csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_indent_labels = one_less_than_current -csharp_using_directive_placement = outside_namespace:silent -csharp_prefer_simple_using_statement = true:suggestion -csharp_prefer_braces = true:silent -csharp_style_namespace_declarations = block_scoped:silent -csharp_style_prefer_method_group_conversion = true:silent -csharp_style_prefer_top_level_statements = true:silent -csharp_style_prefer_primary_constructors = true:suggestion -csharp_style_expression_bodied_lambdas = true:silent -csharp_style_expression_bodied_local_functions = false:silent -csharp_style_prefer_null_check_over_type_check = true:suggestion -csharp_prefer_simple_default_expression = true:suggestion -csharp_style_prefer_local_over_anonymous_function = true:suggestion -csharp_style_prefer_index_operator = true:suggestion -csharp_style_prefer_range_operator = true:suggestion -csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion -csharp_style_prefer_tuple_swap = true:suggestion -csharp_style_prefer_utf8_string_literals = true:suggestion -csharp_style_deconstructed_variable_declaration = true:suggestion -csharp_space_around_binary_operators = before_and_after -csharp_style_unused_value_assignment_preference = discard_variable:suggestion -[*.{cs,vb}] -#### Naming styles #### - -# Naming rules - -dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion -dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface -dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i - -dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.types_should_be_pascal_case.symbols = types -dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case - -dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members -dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case - -# Symbol specifications - -dotnet_naming_symbols.interface.applicable_kinds = interface -dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.interface.required_modifiers = - -dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum -dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.types.required_modifiers = - -dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method -dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.non_field_members.required_modifiers = - -# Naming styles - -dotnet_naming_style.begins_with_i.required_prefix = I -dotnet_naming_style.begins_with_i.required_suffix = -dotnet_naming_style.begins_with_i.word_separator = -dotnet_naming_style.begins_with_i.capitalization = pascal_case - -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = -dotnet_naming_style.pascal_case.capitalization = pascal_case - -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = -dotnet_naming_style.pascal_case.capitalization = pascal_case +csharp_new_line_before_members_in_anonymous_types = true \ No newline at end of file From da5ed33d046f54ef6d8528f7c3bf1f09540d9de5 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Wed, 18 Sep 2024 19:05:46 +0200 Subject: [PATCH 13/19] updated obsolete packages --- src/Dapper.Contrib/Dapper.Contrib.csproj | 8 +++++++ .../Dapper.Tests.Contrib.csproj | 22 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Dapper.Contrib/Dapper.Contrib.csproj b/src/Dapper.Contrib/Dapper.Contrib.csproj index ad614c6e..1ec842c9 100644 --- a/src/Dapper.Contrib/Dapper.Contrib.csproj +++ b/src/Dapper.Contrib/Dapper.Contrib.csproj @@ -19,4 +19,12 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + + \ No newline at end of file diff --git a/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj b/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj index 555e8a01..3d317311 100644 --- a/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj +++ b/tests/Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj @@ -14,10 +14,28 @@ - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + From ccdfc074d2ec16aeff88d63c704b95236c9badf8 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Thu, 19 Sep 2024 08:33:28 +0200 Subject: [PATCH 14/19] rename variable --- src/Dapper.Contrib/SqlMapperExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Dapper.Contrib/SqlMapperExtensions.cs b/src/Dapper.Contrib/SqlMapperExtensions.cs index c95d773a..9dcef24c 100644 --- a/src/Dapper.Contrib/SqlMapperExtensions.cs +++ b/src/Dapper.Contrib/SqlMapperExtensions.cs @@ -291,11 +291,11 @@ private static string GetTableName(Type type) type.GetCustomAttribute(false)?.Name ?? (type.GetCustomAttributes(false).FirstOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic)?.Name; - var schemaAttrr = type.GetCustomAttribute(false)?.Schema; + var tableAttrSchema = type.GetCustomAttribute(false)?.Schema; - if (!string.IsNullOrEmpty(schemaAttrr)) + if (!string.IsNullOrEmpty(tableAttrSchema)) { - tableAttrName = $"{schemaAttrr}.{tableAttrName}"; + tableAttrName = $"{tableAttrSchema}.{tableAttrName}"; } if (tableAttrName != null) From 920421dd6fb6d1708502fff5f47931893b9875a0 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Thu, 19 Sep 2024 11:03:03 +0200 Subject: [PATCH 15/19] update readme --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 9a1fd892..deb4a32f 100644 --- a/Readme.md +++ b/Readme.md @@ -133,10 +133,10 @@ Special Attributes ---------- Dapper.Contrib makes use of some optional attributes: -* `[Table("Tablename")]` - use another table name instead of the (by default pluralized) name of the class +* `[Table("Tablename", Schema = "SchemaName")]` - use another table name instead of the (by default pluralized) name of the class, Schema can be optionally passed as well. ```csharp - [Table ("emps")] + [Table ("emps",Schema = "emp")] public class Employee { public int Id { get; set; } From f816f48fe4464e479d7e87dc426f565376ac6f8c Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Thu, 19 Sep 2024 11:08:43 +0200 Subject: [PATCH 16/19] update readme --- Readme.md | 2 +- src/Dapper.Contrib/SqlMapperExtensions.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index deb4a32f..9acdd59d 100644 --- a/Readme.md +++ b/Readme.md @@ -136,7 +136,7 @@ Dapper.Contrib makes use of some optional attributes: * `[Table("Tablename", Schema = "SchemaName")]` - use another table name instead of the (by default pluralized) name of the class, Schema can be optionally passed as well. ```csharp - [Table ("emps",Schema = "emp")] + [Table ("emps", Schema = "emp")] public class Employee { public int Id { get; set; } diff --git a/src/Dapper.Contrib/SqlMapperExtensions.cs b/src/Dapper.Contrib/SqlMapperExtensions.cs index 9dcef24c..ca0517d5 100644 --- a/src/Dapper.Contrib/SqlMapperExtensions.cs +++ b/src/Dapper.Contrib/SqlMapperExtensions.cs @@ -1,16 +1,16 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; -using System.Text; -using System.Collections.Concurrent; using System.Reflection.Emit; - +using System.Text; using Dapper; namespace Dapper.Contrib.Extensions { + /// /// The Dapper.Contrib extensions for Dapper /// @@ -290,9 +290,9 @@ private static string GetTableName(Type type) var tableAttrName = type.GetCustomAttribute(false)?.Name ?? (type.GetCustomAttributes(false).FirstOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic)?.Name; - + var tableAttrSchema = type.GetCustomAttribute(false)?.Schema; - + if (!string.IsNullOrEmpty(tableAttrSchema)) { tableAttrName = $"{tableAttrSchema}.{tableAttrName}"; From 9a9e58815124ca235d7e02e10447134463f0e084 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Thu, 19 Sep 2024 11:16:27 +0200 Subject: [PATCH 17/19] fix xunit syntax --- tests/Dapper.Tests.Contrib/TestSuite.Async.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/Dapper.Tests.Contrib/TestSuite.Async.cs b/tests/Dapper.Tests.Contrib/TestSuite.Async.cs index fcd11802..465508ee 100644 --- a/tests/Dapper.Tests.Contrib/TestSuite.Async.cs +++ b/tests/Dapper.Tests.Contrib/TestSuite.Async.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Dapper.Contrib.Extensions; -using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute; using Xunit; namespace Dapper.Tests.Contrib @@ -305,9 +304,9 @@ private async Task InsertHelperAsync(Func, T> helper) await connection.DeleteAllAsync().ConfigureAwait(false); var total = await connection.InsertAsync(helper(users)).ConfigureAwait(false); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); } } @@ -343,7 +342,7 @@ private async Task UpdateHelperAsync(Func, T> helper) await connection.DeleteAllAsync().ConfigureAwait(false); var total = await connection.InsertAsync(helper(users)).ConfigureAwait(false); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = connection.Query("select * from Users").ToList(); Assert.Equal(users.Count, numberOfEntities); foreach (var user in users) @@ -377,7 +376,7 @@ public async Task DeleteListAsync() private async Task DeleteHelperAsync(Func, T> helper) where T : class { - const int numberOfEntities = 10; + int numberOfEntities = 10; var users = new List(numberOfEntities); for (var i = 0; i < numberOfEntities; i++) @@ -388,14 +387,14 @@ private async Task DeleteHelperAsync(Func, T> helper) await connection.DeleteAllAsync().ConfigureAwait(false); var total = await connection.InsertAsync(helper(users)).ConfigureAwait(false); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); var usersToDelete = users.Take(10).ToList(); await connection.DeleteAsync(helper(usersToDelete)).ConfigureAwait(false); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities - 10); + Assert.Equal(numberOfEntities - 10, users.Count); } } @@ -413,11 +412,11 @@ public async Task GetAllAsync() await connection.DeleteAllAsync().ConfigureAwait(false); var total = await connection.InsertAsync(users).ConfigureAwait(false); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = (List)await connection.GetAllAsync().ConfigureAwait(false); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); var iusers = await connection.GetAllAsync().ConfigureAwait(false); - Assert.Equal(iusers.ToList().Count, numberOfEntities); + Assert.Equal(numberOfEntities, iusers.ToList().Count); } } From 406df7829a936719ca373c7582e2e34a201d9af9 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Thu, 19 Sep 2024 11:22:59 +0200 Subject: [PATCH 18/19] more xunit warnings removed --- tests/Dapper.Tests.Contrib/TestSuite.cs | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/Dapper.Tests.Contrib/TestSuite.cs b/tests/Dapper.Tests.Contrib/TestSuite.cs index 71dbd8ad..9ff78046 100644 --- a/tests/Dapper.Tests.Contrib/TestSuite.cs +++ b/tests/Dapper.Tests.Contrib/TestSuite.cs @@ -5,8 +5,6 @@ using Dapper.Contrib.Extensions; using Xunit; -using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute; - namespace Dapper.Tests.Contrib { [Table("ObjectX")] @@ -389,9 +387,9 @@ private void InsertHelper(Func, T> helper) connection.DeleteAll(); var total = connection.Insert(helper(users)); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); } } @@ -427,9 +425,9 @@ private void UpdateHelper(Func, T> helper) connection.DeleteAll(); var total = connection.Insert(helper(users)); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); foreach (var user in users) { user.Name += " updated"; @@ -461,7 +459,7 @@ public void DeleteList() private void DeleteHelper(Func, T> helper) where T : class { - const int numberOfEntities = 10; + int numberOfEntities = 10; var users = new List(numberOfEntities); for (var i = 0; i < numberOfEntities; i++) @@ -472,14 +470,14 @@ private void DeleteHelper(Func, T> helper) connection.DeleteAll(); var total = connection.Insert(helper(users)); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); var usersToDelete = users.Take(10).ToList(); connection.Delete(helper(usersToDelete)); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities - 10); + Assert.Equal(numberOfEntities - 10, users.Count); } } @@ -597,13 +595,13 @@ public void GetAll() connection.DeleteAll(); var total = connection.Insert(users); - Assert.Equal(total, numberOfEntities); + Assert.Equal(numberOfEntities, total); users = connection.GetAll().ToList(); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); var iusers = connection.GetAll().ToList(); - Assert.Equal(iusers.Count, numberOfEntities); + Assert.Equal(numberOfEntities, iusers.Count); for (var i = 0; i < numberOfEntities; i++) - Assert.Equal(iusers[i].Age, i); + Assert.Equal(i, iusers[i].Age); } } From b4ac7fb9377d0fbdaff50955cae9eb8caa7d6905 Mon Sep 17 00:00:00 2001 From: Marcin Pluta Date: Thu, 19 Sep 2024 11:36:22 +0200 Subject: [PATCH 19/19] update xunit and add the recommendations --- src/Dapper.Contrib/SqlMapperExtensions.cs | 8 ++++---- tests/Dapper.Tests.Contrib/TestSuite.Async.cs | 8 ++++---- tests/Dapper.Tests.Contrib/TestSuite.cs | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Dapper.Contrib/SqlMapperExtensions.cs b/src/Dapper.Contrib/SqlMapperExtensions.cs index ca0517d5..a6be48d4 100644 --- a/src/Dapper.Contrib/SqlMapperExtensions.cs +++ b/src/Dapper.Contrib/SqlMapperExtensions.cs @@ -186,7 +186,7 @@ public static T Get(this IDbConnection connection, dynamic id, IDbTransaction if (type.IsInterface) { - if (!(connection.Query(sql, dynParams).FirstOrDefault() is IDictionary res)) + if (connection.Query(sql, dynParams).FirstOrDefault() is not IDictionary res) { return null; } @@ -305,7 +305,7 @@ private static string GetTableName(Type type) else { name = type.Name + "s"; - if (type.IsInterface && name.StartsWith("I")) + if (type.IsInterface && name.StartsWith('I')) name = name.Substring(1); } } @@ -607,7 +607,7 @@ public static T GetInterfaceProxy() return (T)Activator.CreateInstance(generatedType); } - private static MethodInfo CreateIsDirtyProperty(TypeBuilder typeBuilder) + private static MethodBuilder CreateIsDirtyProperty(TypeBuilder typeBuilder) { var propType = typeof(bool); var field = typeBuilder.DefineField("_" + nameof(IProxy.IsDirty), propType, FieldAttributes.Private); @@ -648,7 +648,7 @@ private static MethodInfo CreateIsDirtyProperty(TypeBuilder typeBuilder) return currSetPropMthdBldr; } - private static void CreateProperty(TypeBuilder typeBuilder, string propertyName, Type propType, MethodInfo setIsDirtyMethod, bool isIdentity) + private static void CreateProperty(TypeBuilder typeBuilder, string propertyName, Type propType, MethodBuilder setIsDirtyMethod, bool isIdentity) { //Define the field and the property var field = typeBuilder.DefineField("_" + propertyName, propType, FieldAttributes.Private); diff --git a/tests/Dapper.Tests.Contrib/TestSuite.Async.cs b/tests/Dapper.Tests.Contrib/TestSuite.Async.cs index 465508ee..849537c5 100644 --- a/tests/Dapper.Tests.Contrib/TestSuite.Async.cs +++ b/tests/Dapper.Tests.Contrib/TestSuite.Async.cs @@ -124,7 +124,7 @@ public async Task InsertGetUpdateDeleteWithExplicitKeyAsync() var list2 = (await connection.QueryAsync("select * from ObjectY").ConfigureAwait(false)).ToList(); Assert.Equal(list2.Count, originalyCount + 1); o2 = await connection.GetAsync(id).ConfigureAwait(false); - Assert.Equal(o2.ObjectYId, id); + Assert.Equal(id, o2.ObjectYId); o2.Name = "Bar"; await connection.UpdateAsync(o2).ConfigureAwait(false); o2 = await connection.GetAsync(id).ConfigureAwait(false); @@ -344,7 +344,7 @@ private async Task UpdateHelperAsync(Func, T> helper) var total = await connection.InsertAsync(helper(users)).ConfigureAwait(false); Assert.Equal(numberOfEntities, total); users = connection.Query("select * from Users").ToList(); - Assert.Equal(users.Count, numberOfEntities); + Assert.Equal(numberOfEntities, users.Count); foreach (var user in users) { user.Name += " updated"; @@ -435,12 +435,12 @@ public async void GetAsyncAndGetAllAsyncWithNullableValues() Assert.Equal(new DateTime(2011, 07, 14), value1.DateValue.Value); var value2 = await connection.GetAsync(id2).ConfigureAwait(false); - Assert.True(value2.DateValue == null); + Assert.Null(value2.DateValue); var value3 = await connection.GetAllAsync().ConfigureAwait(false); var valuesList = value3.ToList(); Assert.Equal(new DateTime(2011, 07, 14), valuesList[0].DateValue.Value); - Assert.True(valuesList[1].DateValue == null); + Assert.Null(valuesList[1].DateValue); } } diff --git a/tests/Dapper.Tests.Contrib/TestSuite.cs b/tests/Dapper.Tests.Contrib/TestSuite.cs index 9ff78046..8f690de9 100644 --- a/tests/Dapper.Tests.Contrib/TestSuite.cs +++ b/tests/Dapper.Tests.Contrib/TestSuite.cs @@ -245,7 +245,7 @@ public void InsertGetUpdateDeleteWithExplicitKey() var list2 = connection.Query("select * from ObjectY").ToList(); Assert.Equal(list2.Count, originalyCount + 1); o2 = connection.Get(id); - Assert.Equal(o2.ObjectYId, id); + Assert.Equal(id, o2.ObjectYId); o2.Name = "Bar"; connection.Update(o2); o2 = connection.Get(id); @@ -282,7 +282,7 @@ public void InsertGetUpdateDeleteWithExplicitKeyNamedId() var list2 = connection.Query("select * from ObjectZ").ToList(); Assert.Single(list2); o2 = connection.Get(id); - Assert.Equal(o2.Id, id); + Assert.Equal(id, o2.Id); } } @@ -296,7 +296,7 @@ public void ShortIdentity() Assert.True(id > 0); // 1-n are valid here, due to parallel tests var item = connection.Get(id); Assert.Equal(item.TheId, (short)id); - Assert.Equal(item.Name, name); + Assert.Equal(name, item.Name); } } @@ -567,7 +567,7 @@ public void InsertWithCustomTableNameMapper() return tableattr.Name; var name = type.Name + "s"; - if (type.IsInterface && name.StartsWith("I")) + if (type.IsInterface && name.StartsWith('I')) return name.Substring(1); return name; } @@ -620,11 +620,11 @@ public void GetAndGetAllWithNullableValues() Assert.Equal(new DateTime(2011, 07, 14), value1.DateValue.Value); var value2 = connection.Get(id2); - Assert.True(value2.DateValue == null); + Assert.Null(value2.DateValue); var value3 = connection.GetAll().ToList(); Assert.Equal(new DateTime(2011, 07, 14), value3[0].DateValue.Value); - Assert.True(value3[1].DateValue == null); + Assert.Null(value3[1].DateValue); } }