diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 497e5a0bf..3145873c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,11 +43,11 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: '9.0.x' + dotnet-version: '10.0.x' - name: .NET Build run: dotnet build Build.csproj -c Release /p:CI=true - name: Dapper Tests - run: dotnet test tests/Dapper.Tests/Dapper.Tests.csproj -c Release --logger GitHubActions /p:CI=true + run: dotnet test tests/Dapper.Tests/Dapper.Tests.csproj -c Release --logger GitHubActions -p:CI=true -p:TestTfmsInParallel=false 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.; diff --git a/Dapper.SqlBuilder/Readme.md b/Dapper.SqlBuilder/Readme.md index ea69d9b80..5a0968f9f 100644 --- a/Dapper.SqlBuilder/Readme.md +++ b/Dapper.SqlBuilder/Readme.md @@ -85,10 +85,16 @@ var count = conn.ExecuteScalar(countTemplate.RawSql, countTemplate.Paramete Limitations and caveats -------- -OrWhere use `and` not `or` to concat sql problem +### Combining the Where and OrWhere methods -[Issue 647](https://github.com/DapperLib/Dapper/issues/647) +The OrWhere method currently groups all `and` and `or` clauses by type, +then join the groups with `and` or `or` depending on the first call. +This may result in possibly unexpected outcomes. +See also [issue 647](https://github.com/DapperLib/Dapper/issues/647). +#### Example Where first + +When providing the following clauses ```csharp sql.Where("a = @a1"); sql.OrWhere("b = @b1"); @@ -97,11 +103,26 @@ sql.OrWhere("b = @b2"); ``` SqlBuilder will generate sql -```sql= -a = @a1 AND b = @b1 AND a = @a2 AND b = @b2 +```sql +a = @a1 AND a = @a2 AND ( b = @b1 OR b = @b2 ) ``` -not +and not say ```sql a = @a1 OR b = @b1 AND a = @a2 OR b = @b2 ``` + +#### Example OrWhere first + +When providing the following clauses +```csharp +sql.OrWhere("b = @b1"); +sql.Where("a = @a1"); +sql.OrWhere("b = @b2"); +sql.Where("a = @a2"); +``` + +SqlBuilder will generate sql +```sql +a = @a1 OR a = @a2 OR ( b = @b1 OR b = @b2 ) +``` diff --git a/Dapper.StrongName/Dapper.StrongName.csproj b/Dapper.StrongName/Dapper.StrongName.csproj index f202f8f6c..2aae43d73 100644 --- a/Dapper.StrongName/Dapper.StrongName.csproj +++ b/Dapper.StrongName/Dapper.StrongName.csproj @@ -5,7 +5,7 @@ Dapper (Strong Named) A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc. Major Sponsor: Dapper Plus from ZZZ Projects. Sam Saffron;Marc Gravell;Nick Craver - net461;netstandard2.0;net8.0 + net461;netstandard2.0;net8.0;net10.0 true true enable diff --git a/Dapper/Dapper.csproj b/Dapper/Dapper.csproj index af5febfb8..98d8f11eb 100644 --- a/Dapper/Dapper.csproj +++ b/Dapper/Dapper.csproj @@ -5,7 +5,7 @@ orm;sql;micro-orm A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc. Major Sponsor: Dapper Plus from ZZZ Projects. Sam Saffron;Marc Gravell;Nick Craver - net461;netstandard2.0;net8.0 + net461;netstandard2.0;net8.0;net10.0 enable true diff --git a/Dapper/SqlMapper.Async.cs b/Dapper/SqlMapper.Async.cs index fb7ce448c..eade08cb2 100644 --- a/Dapper/SqlMapper.Async.cs +++ b/Dapper/SqlMapper.Async.cs @@ -503,6 +503,7 @@ private static async Task QueryRowAsync(this IDbConnection cnn, Row row, T ThrowZeroRows(row); } while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { /* ignore result sets after the first */ } + command.OnCompleted(); return result; } finally diff --git a/Directory.Packages.props b/Directory.Packages.props index d72d03090..8787a7767 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -35,7 +35,7 @@ - + diff --git a/appveyor.yml b/appveyor.yml index 8c1e48d84..ae9d477bf 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,9 +6,6 @@ skip_commits: files: - '**/*.md' -install: - - choco install dotnet-sdk --version 9.0.101 - environment: Appveyor: true # Postgres diff --git a/build.ps1 b/build.ps1 index f406c745f..59193ff75 100644 --- a/build.ps1 +++ b/build.ps1 @@ -22,8 +22,8 @@ dotnet build ".\Build.csproj" -c Release /p:CI=true Write-Host "Done building." -ForegroundColor "Green" if ($RunTests) { - Write-Host "Running tests: Build.csproj traversal (all frameworks)" -ForegroundColor "Magenta" - dotnet test ".\Build.csproj" -c Release --no-build + Write-Host "Running tests: Build.csproj" -ForegroundColor "Magenta" + dotnet test ".\Build.csproj" -c Release --no-build -p:TestTfmsInParallel=false if ($LastExitCode -ne 0) { Write-Host "Error with tests, aborting build." -Foreground "Red" Exit 1 diff --git a/global.json b/global.json index 2cbaab19b..f7b5e40c2 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.101", + "version": "10.0.102", "rollForward": "latestMajor" } } \ No newline at end of file diff --git a/tests/Dapper.Tests/AsyncTests.cs b/tests/Dapper.Tests/AsyncTests.cs index ec83dc2d9..9c3ec4721 100644 --- a/tests/Dapper.Tests/AsyncTests.cs +++ b/tests/Dapper.Tests/AsyncTests.cs @@ -667,6 +667,34 @@ public async Task TestSupportForDynamicParametersOutputExpressions_Query_Default Assert.Equal(42, result); } + [Fact] + public async Task TestSupportForDynamicParametersOutputExpressions_QueryFirst() + { + var bob = new Person { Name = "bob", PersonId = 1, Address = new Address { PersonId = 2 } }; + + var p = new DynamicParameters(bob); + p.Output(bob, b => b.PersonId); + p.Output(bob, b => b.Occupation); + p.Output(bob, b => b.NumberOfLegs); + p.Output(bob, b => b.Address!.Name); + p.Output(bob, b => b.Address!.PersonId); + + var result = (await connection.QueryFirstAsync(@" +SET @Occupation = 'grillmaster' +SET @PersonId = @PersonId + 1 +SET @NumberOfLegs = @NumberOfLegs - 1 +SET @AddressName = 'bobs burgers' +SET @AddressPersonId = @PersonId +select 42", p).ConfigureAwait(false)); + + Assert.Equal("grillmaster", bob.Occupation); + Assert.Equal(2, bob.PersonId); + Assert.Equal(1, bob.NumberOfLegs); + Assert.Equal("bobs burgers", bob.Address.Name); + Assert.Equal(2, bob.Address.PersonId); + Assert.Equal(42, result); + } + [Fact] public async Task TestSupportForDynamicParametersOutputExpressions_Query_BufferedAsync() { diff --git a/tests/Dapper.Tests/Dapper.Tests.csproj b/tests/Dapper.Tests/Dapper.Tests.csproj index 4c242bf81..e02bb4ba3 100644 --- a/tests/Dapper.Tests/Dapper.Tests.csproj +++ b/tests/Dapper.Tests/Dapper.Tests.csproj @@ -2,7 +2,7 @@ Dapper.Tests Dapper Core Test Suite - net481;net8.0;net9.0 + net481;net8.0;net10.0 $(DefineConstants);MSSQLCLIENT $(NoWarn);IDE0017;IDE0034;IDE0037;IDE0039;IDE0042;IDE0044;IDE0051;IDE0052;IDE0059;IDE0060;IDE0063;IDE1006;xUnit1004;CA1806;CA1816;CA1822;CA1825;CA2208;CA1861 enable