From 88fe33831216a88f9e2aa4451dd7cf6672178b39 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Fri, 23 Oct 2026 18:24:21 +0800 Subject: [PATCH 01/27] Cross-check LibRed against the Microsoft 365 Access Runtime as well as ACE 2016 LibRedAccess ran only on the 2016 Access Database Engine redistributable, which is out of support and differs from the Microsoft 365 runtime the cross-checks are measured on: it knows neither BIGINT nor DATETIME2, cannot evaluate a backtick-quoted CHECK, and leaves a stored query's LvExtra uninitialised. Those cases skip or are masked there, so CI never ran them. The job now has a second leg, 365, which installs the click-to-run Access Runtime (AccessRuntimeRetail, x64, Current channel) through the Office Deployment Tool, fetched from Microsoft's CDN since it downloads the runtime from there anyway. A failed install fails the step. The 2016 leg is unchanged, and the 365 leg is continue-on-error until it proves stable. push.yml and pull_request.yml change alike; CLAUDE.md and AGENTS.md describe the two legs. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/pull_request.yml | 34 +++++++++++++++++++++++++++--- .github/workflows/push.yml | 34 +++++++++++++++++++++++++++--- AGENTS.md | 6 ++++-- CLAUDE.md | 6 ++++-- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f07d3d71..41d6f664 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -692,11 +692,17 @@ jobs: - Preconditions - Changes if: (needs.Preconditions.outputs.lastCommitIsAutoCommit != 'true' || needs.Preconditions.outputs.lastCommitCreatedBeforeSeconds > 300) && needs.Changes.outputs.libred == 'true' + # The 365 leg is new: it does not gate the build until it has proven itself stable. + continue-on-error: ${{ matrix.aceVersion == '365' }} strategy: fail-fast: false matrix: + # 2016 is the out-of-support redistributable; 365 is the current Microsoft 365 Access Runtime, the engine + # the cross-checks are measured on. They differ where a test guards itself (BIGINT/DATETIME2, a + # backtick-quoted CHECK, a stored query's LvExtra), so those cases only run on the 365 leg. aceVersion: - 2016 + - 365 runs-on: windows-latest steps: - name: Checkout @@ -711,9 +717,31 @@ jobs: - name: Install Access Database Engine shell: pwsh run: | - $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' - Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName - & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + if ('${{ matrix.aceVersion }}' -eq '365') + { + # The runtime is click-to-run: the Office Deployment Tool downloads it from Microsoft's CDN, so + # the tool is fetched from there too rather than hosted. + Invoke-WebRequest 'https://officecdn.microsoft.com/pr/wsus/setup.exe' -OutFile setup.exe + Set-Content AccessRuntime.xml @' + + + + + + + + + + '@ + $setup = Start-Process .\setup.exe -ArgumentList '/configure', 'AccessRuntime.xml' -Wait -PassThru + if ($setup.ExitCode -ne 0) { throw "The Office Deployment Tool exited with $($setup.ExitCode)." } + } + else + { + $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' + Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName + & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + } - name: 'ACE Information' shell: pwsh run: | diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 7ecc936b..ea67795e 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -700,11 +700,17 @@ jobs: - Preconditions - Changes if: (needs.Preconditions.outputs.lastCommitIsAutoCommit != 'true' || needs.Preconditions.outputs.lastCommitCreatedBeforeSeconds > 300) && needs.Changes.outputs.libred == 'true' + # The 365 leg is new: it does not gate the build until it has proven itself stable. + continue-on-error: ${{ matrix.aceVersion == '365' }} strategy: fail-fast: false matrix: + # 2016 is the out-of-support redistributable; 365 is the current Microsoft 365 Access Runtime, the engine + # the cross-checks are measured on. They differ where a test guards itself (BIGINT/DATETIME2, a + # backtick-quoted CHECK, a stored query's LvExtra), so those cases only run on the 365 leg. aceVersion: - 2016 + - 365 runs-on: windows-latest steps: - name: Checkout @@ -719,9 +725,31 @@ jobs: - name: Install Access Database Engine shell: pwsh run: | - $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' - Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName - & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + if ('${{ matrix.aceVersion }}' -eq '365') + { + # The runtime is click-to-run: the Office Deployment Tool downloads it from Microsoft's CDN, so + # the tool is fetched from there too rather than hosted. + Invoke-WebRequest 'https://officecdn.microsoft.com/pr/wsus/setup.exe' -OutFile setup.exe + Set-Content AccessRuntime.xml @' + + + + + + + + + + '@ + $setup = Start-Process .\setup.exe -ArgumentList '/configure', 'AccessRuntime.xml' -Wait -PassThru + if ($setup.ExitCode -ne 0) { throw "The Office Deployment Tool exited with $($setup.ExitCode)." } + } + else + { + $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' + Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName + & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + } - name: 'ACE Information' shell: pwsh run: | diff --git a/AGENTS.md b/AGENTS.md index dc322d69..f5534a1d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -405,8 +405,10 @@ flags — `jet` and `libred` — and skips the jobs that don't apply: partway through the largest shard. - **LibRed** — `LibRed.Engine.Tests` and `LibRed.Core.Tests` on Linux/Windows/macOS + ubuntu-arm/windows-arm, no ACE anywhere. -- **LibRedAccess** — the ACE cross-check suites on `windows-latest` with ACE 2016, plus `LibRed.Ado.Tests` and - `LibRed.EFCore.Tests`, which need no driver but run only there for now. +- **LibRedAccess** — the ACE cross-check suites on `windows-latest`, plus `LibRed.Ado.Tests` and + `LibRed.EFCore.Tests`, which need no driver but run only there for now. Two legs: the 2016 redistributable, and + the Microsoft 365 Access Runtime installed through the Office Deployment Tool, where the version-guarded cases + (BIGINT/DATETIME2, backtick CHECKs) actually run. The 365 leg is `continue-on-error` until it proves stable. - **LibRedFunctional** — both `EFCore.LibRed.FunctionalTests` (compatible mode) and `EFCore.LibRed.Extended.FunctionalTests` (extended mode) on the five-platform matrix, `continue-on-error`. - **NuGet** — packs for `master`, `*-servicing`, `*-wip` and release tags, attaching the packages to the run diff --git a/CLAUDE.md b/CLAUDE.md index b4d495c4..3774a127 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -415,8 +415,10 @@ flags — `jet` and `libred` — and skips the jobs that don't apply: partway through the largest shard. - **LibRed** — `LibRed.Engine.Tests` and `LibRed.Core.Tests` on Linux/Windows/macOS + ubuntu-arm/windows-arm, no ACE anywhere. -- **LibRedAccess** — the ACE cross-check suites on `windows-latest` with ACE 2016, plus `LibRed.Ado.Tests` and - `LibRed.EFCore.Tests`, which need no driver but run only there for now. +- **LibRedAccess** — the ACE cross-check suites on `windows-latest`, plus `LibRed.Ado.Tests` and + `LibRed.EFCore.Tests`, which need no driver but run only there for now. Two legs: the 2016 redistributable, and + the Microsoft 365 Access Runtime installed through the Office Deployment Tool, where the version-guarded cases + (BIGINT/DATETIME2, backtick CHECKs) actually run. The 365 leg is `continue-on-error` until it proves stable. - **LibRedFunctional** — both `EFCore.LibRed.FunctionalTests` (compatible mode) and `EFCore.LibRed.Extended.FunctionalTests` (extended mode) on the five-platform matrix, `continue-on-error`. - **NuGet** — packs for `master`, `*-servicing`, `*-wip` and release tags, attaching the packages to the run From 0a5b95e95ed0d5f225ebc8d42382b84f41644b6e Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Fri, 23 Oct 2026 19:45:38 +0800 Subject: [PATCH 02/27] Allow remote-table queries on the Microsoft 365 Access Runtime leg Since the December 2025 Office builds, ACE refuses every query that reaches another file ("Operation is not supported for this type of object") unless AllowQueryRemoteTables is 1. The runtime the 365 leg installs blocks by default, so on its first run the eight IN externaldatabase append and make-table cases of StoredActionQueryWriteAccessTests failed when ACE ran the stored query: the test skips on that message only where ACE creates it, and a stored append or make-table is still created under the block. The install step now sets AllowQueryRemoteTables to 1, as on the machine the cross-checks were measured on, creating the Engines key only where it is missing. The 2016 redistributable does not block, and its leg is unchanged. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/pull_request.yml | 7 +++++++ .github/workflows/push.yml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 41d6f664..1e694832 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -735,6 +735,13 @@ jobs: '@ $setup = Start-Process .\setup.exe -ArgumentList '/configure', 'AccessRuntime.xml' -Wait -PassThru if ($setup.ExitCode -ne 0) { throw "The Office Deployment Tool exited with $($setup.ExitCode)." } + # Since the December 2025 Office builds, ACE refuses every query that reaches another file ("Operation + # is not supported for this type of object") unless AllowQueryRemoteTables is 1. The IN externaldatabase + # cross-checks were measured with it set, as on the developer machine. -Force on an existing registry + # key would wipe its values, so the key is only created when missing. + $engines = 'HKLM:\SOFTWARE\Microsoft\Office\16.0\Access Connectivity Engine\Engines' + if (-not (Test-Path $engines)) { New-Item $engines -Force | Out-Null } + New-ItemProperty $engines -Name AllowQueryRemoteTables -PropertyType DWord -Value 1 -Force | Out-Null } else { diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ea67795e..64a837c4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -743,6 +743,13 @@ jobs: '@ $setup = Start-Process .\setup.exe -ArgumentList '/configure', 'AccessRuntime.xml' -Wait -PassThru if ($setup.ExitCode -ne 0) { throw "The Office Deployment Tool exited with $($setup.ExitCode)." } + # Since the December 2025 Office builds, ACE refuses every query that reaches another file ("Operation + # is not supported for this type of object") unless AllowQueryRemoteTables is 1. The IN externaldatabase + # cross-checks were measured with it set, as on the developer machine. -Force on an existing registry + # key would wipe its values, so the key is only created when missing. + $engines = 'HKLM:\SOFTWARE\Microsoft\Office\16.0\Access Connectivity Engine\Engines' + if (-not (Test-Path $engines)) { New-Item $engines -Force | Out-Null } + New-ItemProperty $engines -Name AllowQueryRemoteTables -PropertyType DWord -Value 1 -Force | Out-Null } else { From 2acd16993b2834448e7cb8daa6e06c767228add3 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Sat, 24 Oct 2026 01:32:27 +0800 Subject: [PATCH 03/27] Contract only lowercase, uppercase or title-case digraphs, as ACE does A contraction was refused only where a lowercase letter met an uppercase one, which holds for every two-letter digraph but not for Hungarian dzs: ACE splits DZs into DZ + s, where LibRed took the whole trigraph. Measured against ACE in every case mix of every contraction order. Co-Authored-By: Claude Opus 5.5 --- src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs | 8 +++++--- src/LibRed/docs/format/page-03-04-index-btree.md | 9 +++++---- .../CreatedDatabaseCollationAccessTests.cs | 5 +++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs b/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs index 820a5318..b11998aa 100644 --- a/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs +++ b/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs @@ -155,8 +155,9 @@ private bool TryLongest(ReadOnlySpan text, int start, out TailoredWeight w { for (int length = Math.Min(MaxLength, text.Length - start); length >= 1; length--) { - // A lowercase letter followed by an uppercase one breaks a contraction, which then falls to a shorter - // match: "cS" is c and S, "dzS" is dz and S, "dZs" is d and zs (verified vs ACE in every digraph order). + // A contraction matches only in lowercase, uppercase or title case; any other mix falls to a shorter + // match: "cS" is c and S, "dzS" is dz and S, "dZs" is d and zs, "DZs" is DZ and s (verified vs ACE in + // every case mix of every contraction). if (BreaksCase(text.Slice(start, length))) continue; if (TryGet(text.Slice(start, length), out weight)) @@ -172,7 +173,8 @@ private bool TryLongest(ReadOnlySpan text, int start, out TailoredWeight w static bool BreaksCase(ReadOnlySpan candidate) { for (int i = 0; i + 1 < candidate.Length; i++) - if (char.IsLower(candidate[i]) && char.IsUpper(candidate[i + 1])) + if ((char.IsLower(candidate[i]) && char.IsUpper(candidate[i + 1])) || + (i > 0 && char.IsUpper(candidate[i]) && char.IsLower(candidate[i + 1]))) return true; return false; } diff --git a/src/LibRed/docs/format/page-03-04-index-btree.md b/src/LibRed/docs/format/page-03-04-index-btree.md index 3d0197e3..15be6904 100644 --- a/src/LibRed/docs/format/page-03-04-index-btree.md +++ b/src/LibRed/docs/format/page-03-04-index-btree.md @@ -691,10 +691,11 @@ to `n` bytes, as page-01 stores it. LibRed builds the row and every key from one `ll`+`ll`. **Only Hungarian doubles** — a doubled digraph is written by doubling its first letter, so `ggy` is `gy`+`gy` (`56 03 56 03`) and `ssz` is `sz`+`sz`, while Czech `cch` is plainly `c`+`ch` (`4D 58 03`) and Spanish `cch` is `c`+`ch`. Doubling has to be tested *before* the plain longest match, - or `ggy` degrades to `g`+`gy`. **Case breaks a contraction** where a lowercase letter is followed by an - uppercase one inside it, and the match falls to a shorter one: `cS`, `sZ`, `gY`, `cH`, `lL`, `lJ` and `dŽ` - are two letters each, Hungarian `dzS` is `dz`+`S` and `dZs` is `d`+`zs` — while `Cs`, `CS`, `Ch`, `Lj` and - `Dž` contract, and so does a doubled `cCs` (verified in every digraph order). A contraction can carry a secondary of its own: Croatian `dž` is + or `ggy` degrades to `g`+`gy`. **A contraction matches only in lowercase, uppercase or title case**; any + other case mix falls to a shorter match: `cS`, `sZ`, `gY`, `cH`, `lL`, `lJ` and `dŽ` are two letters each, + Hungarian `dzS` is `dz`+`S`, `dZs` is `d`+`zs` and `DZs` is `DZ`+`s` — while `Cs`, `CS`, `Ch`, `Lj`, `Dž`, + `Dzs` and `DZS` contract, and so does a doubled `cCs`; a doubled `dDZs` is `dz`+`dz`+`s` (verified in every + case mix of every contraction). A contraction can carry a secondary of its own: Croatian `dž` is `50 04` with secondary `04`, Danish `aa` is `å`'s primary with secondary `03`. - **Expansion** — one character, several primaries. German Phone Book: `ä` = `7F 4A 51 01 00`, primaries `a`+`e` (General has `a` + umlaut secondary); likewise `ö`→`o`+`e`, `ü`→`u`+`e`. Same primitive as diff --git a/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs b/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs index 6b72a6e0..819e0978 100644 --- a/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs +++ b/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs @@ -72,8 +72,9 @@ public class CreatedDatabaseCollationAccessTests(ITestOutputHelper output) "ñ", "č", "ž", "lj", "dž", "ch", "ll", "ı", "İ", "å", "ø", "ß", "เก", "ไทย", "Ω", "б", "א", "一", "漢字", "人々", "カタカナ", "がくせい", "한국", "韓國", @"C:\", - // A digraph in each mix of case — whether a lowercase letter then an uppercase one still contracts. - "cs", "Cs", "cS", "CS", "sz", "Sz", "sZ", "dzs", "Dzs", "dZs", "dzS", "ccs", "cCs", "gy", "gY", "ny", "nY", + // A digraph in each mix of case — only lowercase, uppercase and title case contract. + "cs", "Cs", "cS", "CS", "sz", "Sz", "sZ", "dzs", "Dzs", "dZs", "dzS", "DzS", "DZs", "DZsa", "DZS", "dDZs", + "ccs", "cCs", "gy", "gY", "ny", "nY", "zs", "zS", "ch", "Ch", "cH", "CH", "lj", "Lj", "lJ", "nj", "nJ", "dž", "dŽ", "ll", "lL", "aa", "Aa", "aA", "~sq_cSzallitoLista", ]; From 4723f082d8a3399b88c153271f163154b5b78d15 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Sat, 24 Oct 2026 01:38:22 +0800 Subject: [PATCH 04/27] Return a closing connection's pages in the file's exclusive scope When a connection closes, PageAllocator.ReturnReleasedPages hands back the pages it released and the reservation and groups it holds, rewriting the global usage map on page 1 in a transaction of its own. Every writing statement holds the file's exclusive scope from its first read to its commit; this transaction did not, so a statement on another connection could commit page 1 after the close first wrote it, and the close failed with "Transaction write conflict on page 1". Close and Dispose then threw after the connection's work had already committed, and the pages it should have returned stayed out of the free map. That is MigrationLockConcurrencyTests' intermittent failure on CI: the winning connection releases the lock and closes while seven others keep writing. A stress run of the same pattern (16 connections, no pauses) failed 13 of 16 threads in its first round; it now runs ten rounds clean. The method's body now runs in PageChannel.WriteExclusive, as a statement does, which covers both callers (JetDatabase.Dispose and the encryption path). Its early returns, which read only the connection's own state, stay outside the scope. The bytes written are unchanged. Co-Authored-By: Claude Opus 5.5 --- .../LibRed.Core/Storage/PageAllocator.cs | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/src/LibRed/LibRed.Core/Storage/PageAllocator.cs b/src/LibRed/LibRed.Core/Storage/PageAllocator.cs index 8a353989..92569a9f 100644 --- a/src/LibRed/LibRed.Core/Storage/PageAllocator.cs +++ b/src/LibRed/LibRed.Core/Storage/PageAllocator.cs @@ -446,41 +446,49 @@ public void ReturnReleasedPages() { SortedSet pages = [.. _channel.PagesReleasedAtClose]; if (pages.Count == 0 && !_channel.HasPublishedWrites && _reservationBits == 0 && _groups.Count == 0) return; - (_, MapRecord released) = ReadGlobalMaps(); - // Every bit kept, none bounded by the file: a released page past its end was never materialized, and is - // skipped below. - pages.UnionWith(UsageMap.PagesInRecord(_channel, released.Record, rejectBeyond: null, "The global released-pages map")); - if (pages.Count == 0 && _reservationBits == 0 && _groups.Count == 0) return; - bool ownTransaction = !_channel.InTransaction; - if (ownTransaction) _channel.BeginTransaction(); - try + // In the file's exclusive scope, as a writing statement runs: the global maps are read, rewritten and + // committed with no other connection committing between. Outside it, a statement on another connection + // could commit page 1 after this transaction first wrote it, and the commit would fail as a write conflict. + _channel.WriteExclusive(() => { - // Sized before the merge: a conversion allocates its bitmap pages from the free map as it stands, - // without the pages being released. - if (pages.Count != 0) SizeReleasedMap(pages); - ReturnGroups(); - - // A released page past the end of the file was never materialized; the free map already records - // every page past the end as free. - foreach (int page in pages) - if (page < _channel.PageCount) Free(page); - for (int bit = 0; bit < 32; bit++) - if ((_reservationBits & (1u << bit)) != 0) Free(_reservationStart + bit); - _reservationBits = 0; - _owners.Clear(); - _bitmapSlot = 0; - - (_, released) = ReadGlobalMaps(); - ClearReleasedMap(released); - _channel.ClearPagesReleasedAtClose(); - if (ownTransaction) _channel.CommitTransaction(flush: false); - } - catch - { - if (ownTransaction) _channel.RollbackTransaction(); - throw; - } + (_, MapRecord released) = ReadGlobalMaps(); + // Every bit kept, none bounded by the file: a released page past its end was never materialized, and is + // skipped below. + pages.UnionWith(UsageMap.PagesInRecord(_channel, released.Record, rejectBeyond: null, "The global released-pages map")); + if (pages.Count == 0 && _reservationBits == 0 && _groups.Count == 0) return false; + + bool ownTransaction = !_channel.InTransaction; + if (ownTransaction) _channel.BeginTransaction(); + try + { + // Sized before the merge: a conversion allocates its bitmap pages from the free map as it stands, + // without the pages being released. + if (pages.Count != 0) SizeReleasedMap(pages); + ReturnGroups(); + + // A released page past the end of the file was never materialized; the free map already records + // every page past the end as free. + foreach (int page in pages) + if (page < _channel.PageCount) Free(page); + for (int bit = 0; bit < 32; bit++) + if ((_reservationBits & (1u << bit)) != 0) Free(_reservationStart + bit); + _reservationBits = 0; + _owners.Clear(); + _bitmapSlot = 0; + + (_, released) = ReadGlobalMaps(); + ClearReleasedMap(released); + _channel.ClearPagesReleasedAtClose(); + if (ownTransaction) _channel.CommitTransaction(flush: false); + } + catch + { + if (ownTransaction) _channel.RollbackTransaction(); + throw; + } + return true; + }); } /// From 29ef03215e4eef26151dd2e05b7c1c2cf762577c Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 26 Oct 2026 00:45:42 +0800 Subject: [PATCH 05/27] Add the EF Core 11 RC 2 specification tests the compliance check expects Co-Authored-By: Claude Opus 5.5 --- ...ableSplittingPrimitiveCollectionJetTest.cs | 102 ++++++++ .../NavigationsBulkUpdateJetTest.cs | 158 ++++++++++++ .../NavigationsPrimitiveCollectionJetTest.cs | 181 +++++++++++++ ...edNavigationsPrimitiveCollectionJetTest.cs | 181 +++++++++++++ ...ableSplittingPrimitiveCollectionJetTest.cs | 152 +++++++++++ .../TPCInheritanceJsonQueryJetFixture.cs | 11 + .../TPCInheritanceJsonQueryJetTest.cs | 181 +++++++++++++ ...PCInheritanceTableSplittingQueryJetTest.cs | 175 +++++++++++++ .../TPHInheritanceJsonQueryJetFixture.cs | 11 + .../TPHInheritanceJsonQueryJetTest.cs | 122 +++++++++ ...PHInheritanceTableSplittingQueryJetTest.cs | 125 +++++++++ .../TPTInheritanceJsonQueryJetFixture.cs | 11 + .../TPTInheritanceJsonQueryJetTest.cs | 145 +++++++++++ ...PTInheritanceTableSplittingQueryJetTest.cs | 148 +++++++++++ .../Translations/JsonTranslationsJetTest.cs | 70 +++++ .../RuntimeMigrationJetTest.cs | 20 ++ .../Types/JetTypeFixture.cs | 14 + .../Types/Miscellaneous/JetBoolTypeTest.cs | 238 +++++++++++++++++ .../Miscellaneous/JetByteArrayTypeTest.cs | 220 ++++++++++++++++ .../Types/Miscellaneous/JetGuidTypeTest.cs | 227 +++++++++++++++++ .../Types/Miscellaneous/JetStringTypeTest.cs | 238 +++++++++++++++++ .../Types/Numeric/JetByteTypeTest.cs | 238 +++++++++++++++++ .../Types/Numeric/JetDecimalTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/JetDoubleTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/JetFloatTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/JetIntTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/JetLongTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/JetShortTypeTest.cs | 233 +++++++++++++++++ .../Types/Temporal/JetDateOnlyTypeTest.cs | 239 +++++++++++++++++ .../Types/Temporal/JetDateTime2TypeTest.cs | 239 +++++++++++++++++ .../Temporal/JetDateTimeOffsetTypeTest.cs | 241 ++++++++++++++++++ .../Types/Temporal/JetDateTimeTypeTest.cs | 229 +++++++++++++++++ .../Types/Temporal/JetTimeOnlyTypeTest.cs | 239 +++++++++++++++++ .../Types/Temporal/JetTimeSpanTypeTest.cs | 239 +++++++++++++++++ ...eSplittingPrimitiveCollectionLibRedTest.cs | 102 ++++++++ .../NavigationsBulkUpdateLibRedTest.cs | 156 ++++++++++++ ...avigationsPrimitiveCollectionLibRedTest.cs | 181 +++++++++++++ ...avigationsPrimitiveCollectionLibRedTest.cs | 181 +++++++++++++ ...eSplittingPrimitiveCollectionLibRedTest.cs | 152 +++++++++++ .../TPCInheritanceJsonQueryLibRedFixture.cs | 11 + .../TPCInheritanceJsonQueryLibRedTest.cs | 181 +++++++++++++ ...nheritanceTableSplittingQueryLibRedTest.cs | 175 +++++++++++++ .../TPHInheritanceJsonQueryLibRedFixture.cs | 11 + .../TPHInheritanceJsonQueryLibRedTest.cs | 122 +++++++++ ...nheritanceTableSplittingQueryLibRedTest.cs | 125 +++++++++ .../TPTInheritanceJsonQueryLibRedFixture.cs | 11 + .../TPTInheritanceJsonQueryLibRedTest.cs | 145 +++++++++++ ...nheritanceTableSplittingQueryLibRedTest.cs | 148 +++++++++++ .../JsonTranslationsLibRedTest.cs | 70 +++++ .../RuntimeMigrationLibRedTest.cs | 20 ++ .../Types/LibRedTypeFixture.cs | 14 + .../Types/Miscellaneous/LibRedBoolTypeTest.cs | 234 +++++++++++++++++ .../Miscellaneous/LibRedByteArrayTypeTest.cs | 216 ++++++++++++++++ .../Types/Miscellaneous/LibRedGuidTypeTest.cs | 223 ++++++++++++++++ .../Miscellaneous/LibRedStringTypeTest.cs | 234 +++++++++++++++++ .../Types/Numeric/LibRedByteTypeTest.cs | 234 +++++++++++++++++ .../Types/Numeric/LibRedDecimalTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/LibRedDoubleTypeTest.cs | 229 +++++++++++++++++ .../Types/Numeric/LibRedFloatTypeTest.cs | 229 +++++++++++++++++ .../Types/Numeric/LibRedIntTypeTest.cs | 229 +++++++++++++++++ .../Types/Numeric/LibRedLongTypeTest.cs | 229 +++++++++++++++++ .../Types/Numeric/LibRedShortTypeTest.cs | 229 +++++++++++++++++ .../Types/Temporal/LibRedDateOnlyTypeTest.cs | 235 +++++++++++++++++ .../Types/Temporal/LibRedDateTime2TypeTest.cs | 235 +++++++++++++++++ .../Temporal/LibRedDateTimeOffsetTypeTest.cs | 237 +++++++++++++++++ .../Types/Temporal/LibRedDateTimeTypeTest.cs | 225 ++++++++++++++++ .../Types/Temporal/LibRedTimeOnlyTypeTest.cs | 235 +++++++++++++++++ .../Types/Temporal/LibRedTimeSpanTypeTest.cs | 235 +++++++++++++++++ ...eSplittingPrimitiveCollectionLibRedTest.cs | 102 ++++++++ .../NavigationsBulkUpdateLibRedTest.cs | 158 ++++++++++++ ...avigationsPrimitiveCollectionLibRedTest.cs | 181 +++++++++++++ ...avigationsPrimitiveCollectionLibRedTest.cs | 181 +++++++++++++ ...eSplittingPrimitiveCollectionLibRedTest.cs | 152 +++++++++++ .../TPCInheritanceJsonQueryLibRedFixture.cs | 11 + .../TPCInheritanceJsonQueryLibRedTest.cs | 181 +++++++++++++ ...nheritanceTableSplittingQueryLibRedTest.cs | 175 +++++++++++++ .../TPHInheritanceJsonQueryLibRedFixture.cs | 11 + .../TPHInheritanceJsonQueryLibRedTest.cs | 122 +++++++++ ...nheritanceTableSplittingQueryLibRedTest.cs | 125 +++++++++ .../TPTInheritanceJsonQueryLibRedFixture.cs | 11 + .../TPTInheritanceJsonQueryLibRedTest.cs | 145 +++++++++++ ...nheritanceTableSplittingQueryLibRedTest.cs | 148 +++++++++++ .../JsonTranslationsLibRedTest.cs | 70 +++++ .../RuntimeMigrationLibRedTest.cs | 20 ++ .../Types/LibRedTypeFixture.cs | 14 + .../Types/Miscellaneous/LibRedBoolTypeTest.cs | 238 +++++++++++++++++ .../Miscellaneous/LibRedByteArrayTypeTest.cs | 220 ++++++++++++++++ .../Types/Miscellaneous/LibRedGuidTypeTest.cs | 227 +++++++++++++++++ .../Miscellaneous/LibRedStringTypeTest.cs | 238 +++++++++++++++++ .../Types/Numeric/LibRedByteTypeTest.cs | 238 +++++++++++++++++ .../Types/Numeric/LibRedDecimalTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/LibRedDoubleTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/LibRedFloatTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/LibRedIntTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/LibRedLongTypeTest.cs | 233 +++++++++++++++++ .../Types/Numeric/LibRedShortTypeTest.cs | 233 +++++++++++++++++ .../Types/Temporal/LibRedDateOnlyTypeTest.cs | 239 +++++++++++++++++ .../Types/Temporal/LibRedDateTime2TypeTest.cs | 239 +++++++++++++++++ .../Temporal/LibRedDateTimeOffsetTypeTest.cs | 241 ++++++++++++++++++ .../Types/Temporal/LibRedDateTimeTypeTest.cs | 229 +++++++++++++++++ .../Types/Temporal/LibRedTimeOnlyTypeTest.cs | 239 +++++++++++++++++ .../Types/Temporal/LibRedTimeSpanTypeTest.cs | 239 +++++++++++++++++ 102 files changed, 17310 insertions(+) create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetFixture.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetFixture.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetFixture.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Query/Translations/JsonTranslationsJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/RuntimeMigrationJetTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/JetTypeFixture.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetBoolTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetByteArrayTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetGuidTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetStringTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Numeric/JetByteTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDecimalTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDoubleTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Numeric/JetFloatTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Numeric/JetIntTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Numeric/JetLongTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Numeric/JetShortTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateOnlyTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTime2TypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeOffsetTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeOnlyTypeTest.cs create mode 100644 test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeSpanTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/RuntimeMigrationLibRedTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/LibRedTypeFixture.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs create mode 100644 test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/RuntimeMigrationLibRedTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/LibRedTypeFixture.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs create mode 100644 test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..9a7ede1d --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionJetTest.cs @@ -0,0 +1,102 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.ComplexTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.ComplexTableSplitting; + +public class ComplexTableSplittingPrimitiveCollectionJetTest( + ComplexTableSplittingJetFixture fixture, + ITestOutputHelper testOutputHelper) + : ComplexTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateJetTest.cs new file mode 100644 index 00000000..94788daa --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateJetTest.cs @@ -0,0 +1,158 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System; +using System.Data.Common; +using System.Threading.Tasks; +using Xunit; +using Xunit.Sdk; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsBulkUpdateJetTest(NavigationsJetFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsBulkUpdateRelationalTestBase(fixture, testOutputHelper) +{ + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + // FK constraint failures + public override Task Delete_entity_with_associations() + => Assert.ThrowsAsync(base.Delete_entity_with_associations); + + public override Task Delete_required_associate() + => Assert.ThrowsAsync(base.Delete_required_associate); + + // SQL generation produces invalid object name for these scenarios + public override Task Delete_optional_associate() + => Assert.ThrowsAsync(base.Delete_optional_associate); + + public override Task Update_property_inside_associate() + => Assert.ThrowsAsync(base.Update_property_inside_associate); + + public override Task Update_property_inside_associate_with_special_chars() + => Assert.ThrowsAsync(base.Update_property_inside_associate_with_special_chars); + + public override Task Update_property_on_projected_associate() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate); + + public override Task Update_property_on_projected_associate_with_OrderBy_Skip() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate_with_OrderBy_Skip); + + public override Task Update_multiple_properties_inside_same_associate() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_same_associate); + + public override Task Update_primitive_collection_to_constant() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_constant); + + public override Task Update_primitive_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_parameter); + + // Translation not yet supported for navigation-mapped associations + public override Task Update_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_parameter); + + public override Task Update_associate_to_inline() + => Assert.ThrowsAsync(base.Update_associate_to_inline); + + public override Task Update_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_inline_with_lambda); + + public override Task Update_associate_to_another_associate() + => Assert.ThrowsAsync(base.Update_associate_to_another_associate); + + public override Task Update_associate_to_null() + => Assert.ThrowsAsync(base.Update_associate_to_null); + + public override Task Update_associate_to_null_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_null_with_lambda); + + public override Task Update_associate_to_null_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_null_parameter); + + public override Task Update_nested_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_associate_to_parameter); + + public override Task Update_nested_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_associate_to_inline_with_lambda); + + public override Task Update_nested_associate_to_another_nested_associate() + => Assert.ThrowsAsync(base.Update_nested_associate_to_another_nested_associate); + + public override Task Update_nested_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_collection_to_parameter); + + public override Task Update_nested_collection_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_collection_to_inline_with_lambda); + + public override Task Update_nested_collection_to_another_nested_collection() + => Assert.ThrowsAsync(base.Update_nested_collection_to_another_nested_collection); + + public override Task Update_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_collection_to_parameter); + + public override Task Update_collection_referencing_the_original_collection() + => Assert.ThrowsAsync(base.Update_collection_referencing_the_original_collection); + + public override Task Update_primitive_collection_to_another_collection() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_another_collection); + + public override Task Update_inside_structural_collection() + => Assert.ThrowsAsync(base.Update_inside_structural_collection); + + public override Task Update_multiple_properties_inside_associates_and_on_entity_type() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_associates_and_on_entity_type); + + public override Task Update_multiple_projected_associates_via_anonymous_type() + => Assert.ThrowsAsync(base.Update_multiple_projected_associates_via_anonymous_type); + + public override async Task Update_property_inside_nested_associate() + { + await base.Update_property_inside_nested_associate(); + + AssertExecuteUpdateSql( + """ +@p='foo_updated' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [n] +SET [n].[String] = @p +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +"""); + } + + public override async Task Update_associate_with_null_required_property() + { + await base.Update_associate_with_null_required_property(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_required_nested_associate_to_null() + { + await base.Update_required_nested_associate_to_null(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_inside_primitive_collection() + { + await base.Update_inside_primitive_collection(); + + AssertExecuteUpdateSql( + """ +@p='99' + +SET NOCOUNT OFF; +UPDATE [a0] +SET [a0].[Ints] = JSON_MODIFY([a0].[Ints], '$[1]', @p) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [AssociateType] AS [a0] ON [r].[RequiredAssociateId] = [a0].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) >= 2 +"""); + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..c617fdbf --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionJetTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsPrimitiveCollectionJetTest(NavigationsJetFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE CAST(JSON_VALUE([a].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[OptionalNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a0].[RequiredNestedAssociateId] = [n1].[Id] +LEFT JOIN [NestedAssociateType] AS [n2] ON [a].[OptionalNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([n].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..b2b1a5db --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionJetTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedNavigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.OwnedNavigations; + +public class OwnedNavigationsPrimitiveCollectionJetTest(OwnedNavigationsJetFixture fixture, ITestOutputHelper testOutputHelper) + : OwnedNavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r0].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r0].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r1].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..55ea789e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionJetTest.cs @@ -0,0 +1,152 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.OwnedTableSplitting; + +public class OwnedTableSplittingPrimitiveCollectionJetTest( + OwnedTableSplittingJetFixture fixture, + ITestOutputHelper testOutputHelper) + : OwnedTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r2].[AssociateTypeRootEntityId], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r0].[RootEntityId], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r1].[AssociateTypeRootEntityId], [r1].[AssociateTypeId], [r1].[Id] AS [Id0], [r1].[Int] AS [Int0], [r1].[Ints] AS [Ints0], [r1].[Name] AS [Name0], [r1].[String] AS [String0], [r0].[OptionalNestedAssociate_Id], [r0].[OptionalNestedAssociate_Int], [r0].[OptionalNestedAssociate_Ints], [r0].[OptionalNestedAssociate_Name], [r0].[OptionalNestedAssociate_String], [r0].[RequiredNestedAssociate_Id], [r0].[RequiredNestedAssociate_Int], [r0].[RequiredNestedAssociate_Ints], [r0].[RequiredNestedAssociate_Name], [r0].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r0] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] AND [r0].[Id] = [r1].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r2] ON [r].[Id] = [r2].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r2].[AssociateTypeRootEntityId], [r2].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetFixture.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetFixture.cs new file mode 100644 index 00000000..83156949 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryJetFixture : TPCInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetTest.cs new file mode 100644 index 00000000..f3fd8f84 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryJetTest(TPCInheritanceJsonQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [u].[ParentComplexType] +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([u].[ParentComplexType], '$.Nested') +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryJetTest.cs new file mode 100644 index 00000000..b6524226 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryJetTest.cs @@ -0,0 +1,175 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceTableSplittingQueryJetTest(TPCInheritanceQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetFixture.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetFixture.cs new file mode 100644 index 00000000..bcc605cd --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryJetFixture : TPHInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetTest.cs new file mode 100644 index 00000000..b616a6f3 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetTest.cs @@ -0,0 +1,122 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryJetTest(TPHInheritanceJsonQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPHInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryJetTest.cs new file mode 100644 index 00000000..0f5b3d4a --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryJetTest.cs @@ -0,0 +1,125 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceTableSplittingQueryJetTest( + TPHInheritanceQueryJetFixture fixture, + ITestOutputHelper testOutputHelper) + : TPHInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetFixture.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetFixture.cs new file mode 100644 index 00000000..2a028733 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryJetFixture : TPTInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetTest.cs new file mode 100644 index 00000000..57d513b7 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetTest.cs @@ -0,0 +1,145 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryJetTest(TPTInheritanceJsonQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPTInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryJetTest.cs new file mode 100644 index 00000000..ebb2fe47 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryJetTest.cs @@ -0,0 +1,148 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceTableSplittingQueryJetTest( + TPTInheritanceQueryJetFixture fixture, + ITestOutputHelper testOutputHelper) + : TPTInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Translations/JsonTranslationsJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Translations/JsonTranslationsJetTest.cs new file mode 100644 index 00000000..92b9a42e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Translations/JsonTranslationsJetTest.cs @@ -0,0 +1,70 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Translations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Translations; + +public class JsonTranslationsJetTest : JsonTranslationsRelationalTestBase< + JsonTranslationsJetTest.JsonTranslationsQueryJetFixture> +{ + public JsonTranslationsJetTest(JsonTranslationsQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override async Task JsonPathExists_on_scalar_string_column() + { + await base.JsonPathExists_on_scalar_string_column(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonString], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_complex_property() + { + await base.JsonPathExists_on_complex_property(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonComplexType], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_owned_entity() + { + await base.JsonPathExists_on_owned_entity(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonOwnedType], N'$.OptionalInt') = 1 +"""); + } + + public class JsonTranslationsQueryJetFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory + { + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; + + protected override string RemoveJsonProperty(string column, string property) + => $"JSON_MODIFY({column}, '$.{property}', NULL)"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); +} diff --git a/test/EFCore.Jet.FunctionalTests/RuntimeMigrationJetTest.cs b/test/EFCore.Jet.FunctionalTests/RuntimeMigrationJetTest.cs new file mode 100644 index 00000000..bb566d41 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/RuntimeMigrationJetTest.cs @@ -0,0 +1,20 @@ +using EntityFrameworkCore.Jet.Design.Internal; +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Reflection; + +namespace EntityFrameworkCore.Jet.FunctionalTests; + +public class RuntimeMigrationJetTest(RuntimeMigrationJetTest.RuntimeMigrationJetFixture fixture) + : RuntimeMigrationTestBase(fixture) +{ + protected override Assembly ProviderAssembly + => typeof(JetDesignTimeServices).Assembly; + + public class RuntimeMigrationJetFixture : RuntimeMigrationFixtureBase + { + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/JetTypeFixture.cs b/test/EFCore.Jet.FunctionalTests/Types/JetTypeFixture.cs new file mode 100644 index 00000000..0b9a1e9a --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/JetTypeFixture.cs @@ -0,0 +1,14 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types; + +public abstract class JetTypeFixture : RelationalTypeFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; + + public virtual bool UsingJsonType + => false; +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetBoolTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetBoolTypeTest.cs new file mode 100644 index 00000000..56873c3e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetBoolTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetBoolTypeTest(JetBoolTypeTest.BoolTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(1 AS bit) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bit '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='False' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bit) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bit) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":false,"Value":false}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class BoolTypeFixture : JetTypeFixture + { + public override bool Value { get; } = true; + public override bool OtherValue { get; } = false; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetByteArrayTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetByteArrayTypeTest.cs new file mode 100644 index 00000000..863ddbbe --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetByteArrayTypeTest.cs @@ -0,0 +1,220 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetByteArrayTypeTest(JetByteArrayTypeTest.ByteArrayTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 0x010203 +"""); + } + + // byte[].Equals() does reference equality, so the base test doesn't work for byte arrays + public override Task Primitive_collection_in_query() + => Task.CompletedTask; + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='0x04050607' (Size = 8000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with varbinary even on SQL Server 2025, as that type isn't supported + // (#36627). + // We also can't just wrap JSON_VALUE() with CAST(... AS varbinary(max)), as that would apply a SQL Server binary format + // conversion, and not base64. So we use OPENJSON which does perform base64 conversion. + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +OUTER APPLY OPENJSON([j].[JsonContainer]) WITH ([Value] varbinary(max) '$.Value') AS [v] +WHERE [v].[Value] = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"BAUGBw==","Value":"BAUGBw=="}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteArrayTypeFixture : JetTypeFixture + { + public override byte[] Value { get; } = [1, 2, 3]; + public override byte[] OtherValue { get; } = [4, 5, 6, 7]; + + public override Func Comparer { get; } = (a, b) => a.SequenceEqual(b); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetGuidTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetGuidTypeTest.cs new file mode 100644 index 00000000..fac28920 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetGuidTypeTest.cs @@ -0,0 +1,227 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetGuidTypeTest(JetGuidTypeTest.GuidTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '8f7331d6-cde9-44fb-8611-81fff686f280' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] uniqueidentifier '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='ae192c36-9004-49b2-b785-8be10d169627' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with uniqueidentifier even on SQL Server 2025, as that type isn't + // supported (#36627). + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS uniqueidentifier) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"ae192c36-9004-49b2-b785-8be10d169627","Value":"ae192c36-9004-49b2-b785-8be10d169627"}' (Nullable = false) (Size = 100) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class GuidTypeFixture : JetTypeFixture + { + public override Guid Value { get; } = new("8f7331d6-cde9-44fb-8611-81fff686f280"); + public override Guid OtherValue { get; } = new("ae192c36-9004-49b2-b785-8be10d169627"); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetStringTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetStringTypeTest.cs new file mode 100644 index 00000000..e21ef4da --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetStringTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetStringTypeTest(JetStringTypeTest.StringTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = N'foo' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] nvarchar(max) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='bar' (Size = 4000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING nvarchar(max)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value') = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"bar","Value":"bar"}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class StringTypeFixture : JetTypeFixture + { + public override string Value { get; } = "foo"; + public override string OtherValue { get; } = "bar"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetByteTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetByteTypeTest.cs new file mode 100644 index 00000000..c6669c59 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetByteTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetByteTypeTest(JetByteTypeTest.ByteTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(0 AS tinyint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] tinyint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='255' (Size = 1) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING tinyint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS tinyint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":255,"Value":255}' (Nullable = false) (Size = 30) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteTypeFixture : JetTypeFixture + { + public override byte Value { get; } = byte.MinValue; + public override byte OtherValue { get; } = byte.MaxValue; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDecimalTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDecimalTypeTest.cs new file mode 100644 index 00000000..0a889371 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDecimalTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetDecimalTypeTest(JetDecimalTypeTest.DecimalTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] decimal(18,2) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' (Precision = 18) (Scale = 2) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING decimal(18,2)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS decimal(18,2)) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DecimalTypeFixture : JetTypeFixture + { + public override decimal Value { get; } = 30.5m; + public override decimal OtherValue { get; } = 30m; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDoubleTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDoubleTypeTest.cs new file mode 100644 index 00000000..63530063 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDoubleTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetDoubleTypeTest(JetDoubleTypeTest.DoubleTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5E0 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] float '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING float) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS float) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DoubleTypeFixture : JetTypeFixture + { + public override double Value { get; } = 30.5d; + public override double OtherValue { get; } = 30d; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetFloatTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetFloatTypeTest.cs new file mode 100644 index 00000000..1d58b760 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetFloatTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetFloatTypeTest(JetFloatTypeTest.FloatTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(30.5 AS real) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] real '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING real) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS real) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class FloatTypeFixture : JetTypeFixture + { + public override float Value { get; } = 30.5f; + public override float OtherValue { get; } = 30f; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetIntTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetIntTypeTest.cs new file mode 100644 index 00000000..b91e050c --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetIntTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetIntTypeTest(JetIntTypeTest.IntTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = -2147483648 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] int '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2147483647' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING int) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS int) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":2147483647,"Value":2147483647}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class IntTypeFixture : JetTypeFixture + { + public override int Value { get; } = int.MinValue; + public override int OtherValue { get; } = int.MaxValue; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetLongTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetLongTypeTest.cs new file mode 100644 index 00000000..cdf0ab18 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetLongTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetLongTypeTest(JetLongTypeTest.LongTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-9223372036854775808 AS bigint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bigint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='9223372036854775807' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bigint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bigint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":9223372036854775807,"Value":9223372036854775807}' (Nullable = false) (Size = 62) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class LongTypeFixture : JetTypeFixture + { + public override long Value { get; } = long.MinValue; + public override long OtherValue { get; } = long.MaxValue; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetShortTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetShortTypeTest.cs new file mode 100644 index 00000000..07bc9f7e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetShortTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetShortTypeTest(JetShortTypeTest.ShortTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-32768 AS smallint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] smallint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='32767' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING smallint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS smallint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":32767,"Value":32767}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ShortTypeFixture : JetTypeFixture + { + public override short Value { get; } = short.MinValue; + public override short OtherValue { get; } = short.MaxValue; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateOnlyTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateOnlyTypeTest.cs new file mode 100644 index 00000000..a20b0e83 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateOnlyTypeTest(JetDateOnlyTypeTest.DateTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] date '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='05/03/2022' (DbType = Date) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING date) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS date) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03","Value":"2022-05-03"}' (Nullable = false) (Size = 48) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTypeFixture : JetTypeFixture + { + public override DateOnly Value { get; } = new(2020, 1, 5); + public override DateOnly OtherValue { get; } = new(2022, 5, 3); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTime2TypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTime2TypeTest.cs new file mode 100644 index 00000000..dbdd8eb8 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTime2TypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateTime2TypeTest(JetDateTime2TypeTest.DateTime2TypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime2 '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetime2) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime2) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTime2TypeFixture : JetTypeFixture + { + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeOffsetTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeOffsetTypeTest.cs new file mode 100644 index 00000000..cb95f948 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeOffsetTypeTest.cs @@ -0,0 +1,241 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateTimeOffsetTypeTest( + JetDateTimeOffsetTypeTest.DateTimeOffsetTypeFixture fixture, + ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000+02:00' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetimeoffset '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2020-01-05T12:30:45.0000000+03:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetimeoffset) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetimeoffset) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2020-01-05T12:30:45+03:00","Value":"2020-01-05T12:30:45+03:00"}' (Nullable = false) (Size = 78) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeOffsetTypeFixture : JetTypeFixture + { + public override DateTimeOffset Value { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(2)); + public override DateTimeOffset OtherValue { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(3)); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeTypeTest.cs new file mode 100644 index 00000000..b15753ba --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeTypeTest.cs @@ -0,0 +1,229 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateTimeTypeTest(JetDateTimeTypeTest.DateTimeTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeTypeFixture : JetTypeFixture + { + // The default mapping for .NET DateTime is datetime2; this tests the non-default (and discouraged) datetime type. + public override string StoreType + => "datetime"; + + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeOnlyTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeOnlyTypeTest.cs new file mode 100644 index 00000000..f6a1869c --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetTimeOnlyTypeTest(JetTimeOnlyTypeTest.TimeOnlyTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00' (DbType = Time) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00.0000000","Value":"14:00:00.0000000"}' (Nullable = false) (Size = 60) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeOnlyTypeFixture : JetTypeFixture + { + public override TimeOnly Value { get; } = new(12, 30, 45); + public override TimeOnly OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeSpanTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeSpanTypeTest.cs new file mode 100644 index 00000000..9cd8be76 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeSpanTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetTimeSpanTypeTest(JetTimeSpanTypeTest.TimeSpanTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00","Value":"14:00:00"}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeSpanTypeFixture : JetTypeFixture + { + public override TimeSpan Value { get; } = new(12, 30, 45); + public override TimeSpan OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..178ca109 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,102 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.ComplexTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.ComplexTableSplitting; + +public class ComplexTableSplittingPrimitiveCollectionLibRedTest( + ComplexTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : ComplexTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs new file mode 100644 index 00000000..75c3ab7b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs @@ -0,0 +1,156 @@ +using System; +using System.Data.Common; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; +using Xunit.Sdk; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsBulkUpdateLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsBulkUpdateRelationalTestBase(fixture, testOutputHelper) +{ + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + // FK constraint failures + public override Task Delete_entity_with_associations() + => Assert.ThrowsAsync(base.Delete_entity_with_associations); + + public override Task Delete_required_associate() + => Assert.ThrowsAsync(base.Delete_required_associate); + + // SQL generation produces invalid object name for these scenarios + public override Task Delete_optional_associate() + => Assert.ThrowsAsync(base.Delete_optional_associate); + + public override Task Update_property_inside_associate() + => Assert.ThrowsAsync(base.Update_property_inside_associate); + + public override Task Update_property_inside_associate_with_special_chars() + => Assert.ThrowsAsync(base.Update_property_inside_associate_with_special_chars); + + public override Task Update_property_on_projected_associate() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate); + + public override Task Update_property_on_projected_associate_with_OrderBy_Skip() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate_with_OrderBy_Skip); + + public override Task Update_multiple_properties_inside_same_associate() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_same_associate); + + public override Task Update_primitive_collection_to_constant() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_constant); + + public override Task Update_primitive_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_parameter); + + // Translation not yet supported for navigation-mapped associations + public override Task Update_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_parameter); + + public override Task Update_associate_to_inline() + => Assert.ThrowsAsync(base.Update_associate_to_inline); + + public override Task Update_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_inline_with_lambda); + + public override Task Update_associate_to_another_associate() + => Assert.ThrowsAsync(base.Update_associate_to_another_associate); + + public override Task Update_associate_to_null() + => Assert.ThrowsAsync(base.Update_associate_to_null); + + public override Task Update_associate_to_null_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_null_with_lambda); + + public override Task Update_associate_to_null_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_null_parameter); + + public override Task Update_nested_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_associate_to_parameter); + + public override Task Update_nested_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_associate_to_inline_with_lambda); + + public override Task Update_nested_associate_to_another_nested_associate() + => Assert.ThrowsAsync(base.Update_nested_associate_to_another_nested_associate); + + public override Task Update_nested_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_collection_to_parameter); + + public override Task Update_nested_collection_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_collection_to_inline_with_lambda); + + public override Task Update_nested_collection_to_another_nested_collection() + => Assert.ThrowsAsync(base.Update_nested_collection_to_another_nested_collection); + + public override Task Update_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_collection_to_parameter); + + public override Task Update_collection_referencing_the_original_collection() + => Assert.ThrowsAsync(base.Update_collection_referencing_the_original_collection); + + public override Task Update_primitive_collection_to_another_collection() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_another_collection); + + public override Task Update_inside_structural_collection() + => Assert.ThrowsAsync(base.Update_inside_structural_collection); + + public override Task Update_multiple_properties_inside_associates_and_on_entity_type() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_associates_and_on_entity_type); + + public override Task Update_multiple_projected_associates_via_anonymous_type() + => Assert.ThrowsAsync(base.Update_multiple_projected_associates_via_anonymous_type); + + public override async Task Update_property_inside_nested_associate() + { + await base.Update_property_inside_nested_associate(); + + AssertExecuteUpdateSql( + """ +@p='foo_updated' (Size = 255) + +UPDATE `RootEntity` AS `r` +INNER JOIN `AssociateType` AS `a` ON `r`.`RequiredAssociateId` = `a`.`Id` +INNER JOIN `NestedAssociateType` AS `n` ON `a`.`RequiredNestedAssociateId` = `n`.`Id` +SET `n`.`String` = @p +"""); + } + + public override async Task Update_associate_with_null_required_property() + { + await base.Update_associate_with_null_required_property(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_required_nested_associate_to_null() + { + await base.Update_required_nested_associate_to_null(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_inside_primitive_collection() + { + await base.Update_inside_primitive_collection(); + + AssertExecuteUpdateSql( + """ +@p='99' + +SET NOCOUNT OFF; +UPDATE [a0] +SET [a0].[Ints] = JSON_MODIFY([a0].[Ints], '$[1]', @p) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [AssociateType] AS [a0] ON [r].[RequiredAssociateId] = [a0].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) >= 2 +"""); + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..fca96458 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsPrimitiveCollectionLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE CAST(JSON_VALUE([a].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[OptionalNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a0].[RequiredNestedAssociateId] = [n1].[Id] +LEFT JOIN [NestedAssociateType] AS [n2] ON [a].[OptionalNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([n].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..d0d3ccde --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedNavigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.OwnedNavigations; + +public class OwnedNavigationsPrimitiveCollectionLibRedTest(OwnedNavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : OwnedNavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r0].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r0].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r1].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..eb7c7174 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,152 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.OwnedTableSplitting; + +public class OwnedTableSplittingPrimitiveCollectionLibRedTest( + OwnedTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : OwnedTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r2].[AssociateTypeRootEntityId], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r0].[RootEntityId], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r1].[AssociateTypeRootEntityId], [r1].[AssociateTypeId], [r1].[Id] AS [Id0], [r1].[Int] AS [Int0], [r1].[Ints] AS [Ints0], [r1].[Name] AS [Name0], [r1].[String] AS [String0], [r0].[OptionalNestedAssociate_Id], [r0].[OptionalNestedAssociate_Int], [r0].[OptionalNestedAssociate_Ints], [r0].[OptionalNestedAssociate_Name], [r0].[OptionalNestedAssociate_String], [r0].[RequiredNestedAssociate_Id], [r0].[RequiredNestedAssociate_Int], [r0].[RequiredNestedAssociate_Ints], [r0].[RequiredNestedAssociate_Name], [r0].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r0] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] AND [r0].[Id] = [r1].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r2] ON [r].[Id] = [r2].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r2].[AssociateTypeRootEntityId], [r2].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..a856cb33 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedFixture : TPCInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..b10da1aa --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,181 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedTest(TPCInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType` +FROM `Coke` AS `c` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `u`.`ParentComplexType` +FROM ( + SELECT `d`.`ParentComplexType` + FROM `Drinks` AS `d` + UNION ALL + SELECT `c`.`ParentComplexType` + FROM `Coke` AS `c` + UNION ALL + SELECT `l`.`ParentComplexType` + FROM `Lilt` AS `l` + UNION ALL + SELECT `t`.`ParentComplexType` + FROM `Tea` AS `t` +) AS `u` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([u].[ParentComplexType], '$.Nested') +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..4b6dfe40 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,175 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceTableSplittingQueryLibRedTest(TPCInheritanceQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ComplexTypeCollection`, `c`.`Int`, `c`.`UniqueInt`, `c`.`NestedInt`, `c`.`NestedComplexType_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +WHERE `c`.`ChildComplexType_Int` = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `u`.`Id`, `u`.`SortIndex`, `u`.`CaffeineGrams`, `u`.`CokeCO2`, `u`.`Ints`, `u`.`SugarGrams`, `u`.`LiltCO2`, `u`.`SugarGrams1`, `u`.`CaffeineGrams1`, `u`.`HasMilk`, `u`.`ComplexTypeCollection`, `u`.`ParentComplexType_Int`, `u`.`ParentComplexType_UniqueInt`, `u`.`ParentComplexType_Nested_NestedInt`, `u`.`ParentComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int`, `u`.`ChildComplexType_UniqueInt`, `u`.`ChildComplexType_Nested_NestedInt`, `u`.`ChildComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int1`, `u`.`ChildComplexType_UniqueInt1`, `u`.`ChildComplexType_Nested_NestedInt1`, `u`.`ChildComplexType_Nested_UniqueInt1`, `u`.`Discriminator` +FROM ( + SELECT `d`.`Id`, `d`.`SortIndex`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Drink' AS `Discriminator` + FROM `Drinks` AS `d` + UNION ALL + SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`ComplexTypeCollection`, `c`.`Int` AS `ParentComplexType_Int`, `c`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Coke' AS `Discriminator` + FROM `Coke` AS `c` + UNION ALL + SELECT `l`.`Id`, `l`.`SortIndex`, `l`.`ComplexTypeCollection`, `l`.`Int` AS `ParentComplexType_Int`, `l`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, `l`.`LiltCO2`, `l`.`SugarGrams` AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Lilt' AS `Discriminator` + FROM `Lilt` AS `l` + UNION ALL + SELECT `t`.`Id`, `t`.`SortIndex`, `t`.`ComplexTypeCollection`, `t`.`Int` AS `ParentComplexType_Int`, `t`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, `t`.`CaffeineGrams` AS `CaffeineGrams1`, `t`.`HasMilk`, `t`.`ChildComplexType_Int` AS `ChildComplexType_Int1`, `t`.`ChildComplexType_UniqueInt` AS `ChildComplexType_UniqueInt1`, `t`.`ChildComplexType_Nested_NestedInt` AS `ChildComplexType_Nested_NestedInt1`, `t`.`ChildComplexType_Nested_UniqueInt` AS `ChildComplexType_Nested_UniqueInt1`, 'Tea' AS `Discriminator` + FROM `Tea` AS `t` +) AS `u` +WHERE `u`.`ParentComplexType_Int` = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ComplexTypeCollection`, `c`.`Int`, `c`.`UniqueInt`, `c`.`NestedInt`, `c`.`NestedComplexType_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +WHERE `c`.`ChildComplexType_Nested_NestedInt` = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `u`.`Id`, `u`.`SortIndex`, `u`.`CaffeineGrams`, `u`.`CokeCO2`, `u`.`Ints`, `u`.`SugarGrams`, `u`.`LiltCO2`, `u`.`SugarGrams1`, `u`.`CaffeineGrams1`, `u`.`HasMilk`, `u`.`ComplexTypeCollection`, `u`.`ParentComplexType_Int`, `u`.`ParentComplexType_UniqueInt`, `u`.`ParentComplexType_Nested_NestedInt`, `u`.`ParentComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int`, `u`.`ChildComplexType_UniqueInt`, `u`.`ChildComplexType_Nested_NestedInt`, `u`.`ChildComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int1`, `u`.`ChildComplexType_UniqueInt1`, `u`.`ChildComplexType_Nested_NestedInt1`, `u`.`ChildComplexType_Nested_UniqueInt1`, `u`.`Discriminator` +FROM ( + SELECT `d`.`Id`, `d`.`SortIndex`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Drink' AS `Discriminator` + FROM `Drinks` AS `d` + UNION ALL + SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`ComplexTypeCollection`, `c`.`Int` AS `ParentComplexType_Int`, `c`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Coke' AS `Discriminator` + FROM `Coke` AS `c` + UNION ALL + SELECT `l`.`Id`, `l`.`SortIndex`, `l`.`ComplexTypeCollection`, `l`.`Int` AS `ParentComplexType_Int`, `l`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, `l`.`LiltCO2`, `l`.`SugarGrams` AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Lilt' AS `Discriminator` + FROM `Lilt` AS `l` + UNION ALL + SELECT `t`.`Id`, `t`.`SortIndex`, `t`.`ComplexTypeCollection`, `t`.`Int` AS `ParentComplexType_Int`, `t`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, `t`.`CaffeineGrams` AS `CaffeineGrams1`, `t`.`HasMilk`, `t`.`ChildComplexType_Int` AS `ChildComplexType_Int1`, `t`.`ChildComplexType_UniqueInt` AS `ChildComplexType_UniqueInt1`, `t`.`ChildComplexType_Nested_NestedInt` AS `ChildComplexType_Nested_NestedInt1`, `t`.`ChildComplexType_Nested_UniqueInt` AS `ChildComplexType_Nested_UniqueInt1`, 'Tea' AS `Discriminator` + FROM `Tea` AS `t` +) AS `u` +WHERE `u`.`ParentComplexType_Nested_NestedInt` = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +UNION ALL +SELECT `c`.`Int` AS `ParentComplexType_Int`, `c`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +UNION ALL +SELECT `l`.`Int` AS `ParentComplexType_Int`, `l`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Lilt` AS `l` +UNION ALL +SELECT `t`.`Int` AS `ParentComplexType_Int`, `t`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Tea` AS `t` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +UNION ALL +SELECT `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +UNION ALL +SELECT `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Lilt` AS `l` +UNION ALL +SELECT `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Tea` AS `t` +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..e6509b0b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedFixture : TPHInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..d067147e --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,122 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedTest(TPHInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPHInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`ChildComplexType` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..3efa7383 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,125 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceTableSplittingQueryLibRedTest( + TPHInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPHInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 AND `d`.`ChildComplexType_Int` = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`LiltCO2`, `d`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt`, `d`.`Tea_ChildComplexType_Int`, `d`.`Tea_ChildComplexType_UniqueInt`, `d`.`Tea_ChildComplexType_Nested_NestedInt`, `d`.`Tea_ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`ParentComplexType_Int` = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 AND `d`.`ChildComplexType_Nested_NestedInt` = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`LiltCO2`, `d`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt`, `d`.`Tea_ChildComplexType_Int`, `d`.`Tea_ChildComplexType_UniqueInt`, `d`.`Tea_ChildComplexType_Nested_NestedInt`, `d`.`Tea_ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`ParentComplexType_Nested_NestedInt` = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..2c2f057b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedFixture : TPTInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..b019b594 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,145 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedTest(TPTInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPTInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..4017b3ab --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,148 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceTableSplittingQueryLibRedTest( + TPTInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPTInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +WHERE `c`.`ChildComplexType_Int` = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `l`.`LiltCO2`, `l`.`SugarGrams`, `t`.`CaffeineGrams`, `t`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, `t`.`ChildComplexType_Int`, `t`.`ChildComplexType_UniqueInt`, `t`.`ChildComplexType_Nested_NestedInt`, `t`.`ChildComplexType_Nested_UniqueInt`, CASE + WHEN `t`.`Id` IS NOT NULL THEN 'Tea' + WHEN `l`.`Id` IS NOT NULL THEN 'Lilt' + WHEN `c`.`Id` IS NOT NULL THEN 'Coke' +END AS `Discriminator` +FROM `Drinks` AS `d` +LEFT JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +LEFT JOIN `Lilt` AS `l` ON `d`.`Id` = `l`.`Id` +LEFT JOIN `Tea` AS `t` ON `d`.`Id` = `t`.`Id` +WHERE `d`.`ParentComplexType_Int` = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +WHERE `c`.`ChildComplexType_Nested_NestedInt` = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `l`.`LiltCO2`, `l`.`SugarGrams`, `t`.`CaffeineGrams`, `t`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, `t`.`ChildComplexType_Int`, `t`.`ChildComplexType_UniqueInt`, `t`.`ChildComplexType_Nested_NestedInt`, `t`.`ChildComplexType_Nested_UniqueInt`, CASE + WHEN `t`.`Id` IS NOT NULL THEN 'Tea' + WHEN `l`.`Id` IS NOT NULL THEN 'Lilt' + WHEN `c`.`Id` IS NOT NULL THEN 'Coke' +END AS `Discriminator` +FROM `Drinks` AS `d` +LEFT JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +LEFT JOIN `Lilt` AS `l` ON `d`.`Id` = `l`.`Id` +LEFT JOIN `Tea` AS `t` ON `d`.`Id` = `t`.`Id` +WHERE `d`.`ParentComplexType_Nested_NestedInt` = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs new file mode 100644 index 00000000..647c6fe1 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs @@ -0,0 +1,70 @@ +using System.Threading.Tasks; +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Translations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Translations; + +public class JsonTranslationsLibRedTest : JsonTranslationsRelationalTestBase< + JsonTranslationsLibRedTest.JsonTranslationsQueryLibRedFixture> +{ + public JsonTranslationsLibRedTest(JsonTranslationsQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override async Task JsonPathExists_on_scalar_string_column() + { + await base.JsonPathExists_on_scalar_string_column(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonString], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_complex_property() + { + await base.JsonPathExists_on_complex_property(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonComplexType], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_owned_entity() + { + await base.JsonPathExists_on_owned_entity(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonOwnedType], N'$.OptionalInt') = 1 +"""); + } + + public class JsonTranslationsQueryLibRedFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + protected override string RemoveJsonProperty(string column, string property) + => $"JSON_MODIFY({column}, '$.{property}', NULL)"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/RuntimeMigrationLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/RuntimeMigrationLibRedTest.cs new file mode 100644 index 00000000..0586fffe --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/RuntimeMigrationLibRedTest.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using EntityFrameworkCore.LibRed.Design.Internal; +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests; + +public class RuntimeMigrationLibRedTest(RuntimeMigrationLibRedTest.RuntimeMigrationLibRedFixture fixture) + : RuntimeMigrationTestBase(fixture) +{ + protected override Assembly ProviderAssembly + => typeof(LibRedDesignTimeServices).Assembly; + + public class RuntimeMigrationLibRedFixture : RuntimeMigrationFixtureBase + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/LibRedTypeFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/LibRedTypeFixture.cs new file mode 100644 index 00000000..ffab697b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/LibRedTypeFixture.cs @@ -0,0 +1,14 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types; + +public abstract class LibRedTypeFixture : RelationalTypeFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + public virtual bool UsingJsonType + => false; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs new file mode 100644 index 00000000..29455462 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs @@ -0,0 +1,234 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedBoolTypeTest(LibRedBoolTypeTest.BoolTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bit '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='False' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bit) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bit) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":false,"Value":false}' (Nullable = false) (Size = 34) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class BoolTypeFixture : LibRedTypeFixture + { + public override bool Value { get; } = true; + public override bool OtherValue { get; } = false; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs new file mode 100644 index 00000000..b9237875 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs @@ -0,0 +1,216 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedByteArrayTypeTest(LibRedByteArrayTypeTest.ByteArrayTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 510) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 0x010203 +"""); + } + + // byte[].Equals() does reference equality, so the base test doesn't work for byte arrays + public override Task Primitive_collection_in_query() + => Task.CompletedTask; + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='0x04050607' (Size = 510) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with varbinary even on SQL Server 2025, as that type isn't supported + // (#36627). + // We also can't just wrap JSON_VALUE() with CAST(... AS varbinary(max)), as that would apply a SQL Server binary format + // conversion, and not base64. So we use OPENJSON which does perform base64 conversion. + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +OUTER APPLY OPENJSON([j].[JsonContainer]) WITH ([Value] varbinary(max) '$.Value') AS [v] +WHERE [v].[Value] = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"BAUGBw==","Value":"BAUGBw=="}' (Nullable = false) (Size = 44) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteArrayTypeFixture : LibRedTypeFixture + { + public override byte[] Value { get; } = [1, 2, 3]; + public override byte[] OtherValue { get; } = [4, 5, 6, 7]; + + public override Func Comparer { get; } = (a, b) => a.SequenceEqual(b); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs new file mode 100644 index 00000000..d0c2d883 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs @@ -0,0 +1,223 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedGuidTypeTest(LibRedGuidTypeTest.GuidTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = {8f7331d6-cde9-44fb-8611-81fff686f280} +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] uniqueidentifier '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='ae192c36-9004-49b2-b785-8be10d169627' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with uniqueidentifier even on SQL Server 2025, as that type isn't + // supported (#36627). + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS uniqueidentifier) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"ae192c36-9004-49b2-b785-8be10d169627","Value":"ae192c36-9004-49b2-b785-8be10d169627"}' (Nullable = false) (Size = 100) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class GuidTypeFixture : LibRedTypeFixture + { + public override Guid Value { get; } = new("8f7331d6-cde9-44fb-8611-81fff686f280"); + public override Guid OtherValue { get; } = new("ae192c36-9004-49b2-b785-8be10d169627"); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs new file mode 100644 index 00000000..588eeb5d --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs @@ -0,0 +1,234 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedStringTypeTest(LibRedStringTypeTest.StringTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='foo' (Size = 255) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 'foo' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] nvarchar(max) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='bar' (Size = 255) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING nvarchar(max)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value') = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"bar","Value":"bar"}' (Nullable = false) (Size = 34) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class StringTypeFixture : LibRedTypeFixture + { + public override string Value { get; } = "foo"; + public override string OtherValue { get; } = "bar"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs new file mode 100644 index 00000000..40424d85 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs @@ -0,0 +1,234 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedByteTypeTest(LibRedByteTypeTest.ByteTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = CBYTE(0) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] tinyint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='255' (Size = 1) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING tinyint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS tinyint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":255,"Value":255}' (Nullable = false) (Size = 30) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteTypeFixture : LibRedTypeFixture + { + public override byte Value { get; } = byte.MinValue; + public override byte OtherValue { get; } = byte.MaxValue; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs new file mode 100644 index 00000000..7abc7262 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs @@ -0,0 +1,233 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedDecimalTypeTest(LibRedDecimalTypeTest.DecimalTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] decimal(18,2) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' (Precision = 18) (Scale = 2) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING decimal(18,2)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS decimal(18,2)) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DecimalTypeFixture : LibRedTypeFixture + { + public override decimal Value { get; } = 30.5m; + public override decimal OtherValue { get; } = 30m; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs new file mode 100644 index 00000000..f4c98503 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedDoubleTypeTest(LibRedDoubleTypeTest.DoubleTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] float '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING float) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS float) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DoubleTypeFixture : LibRedTypeFixture + { + public override double Value { get; } = 30.5d; + public override double OtherValue { get; } = 30d; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs new file mode 100644 index 00000000..173ade0c --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedFloatTypeTest(LibRedFloatTypeTest.FloatTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] real '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING real) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS real) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class FloatTypeFixture : LibRedTypeFixture + { + public override float Value { get; } = 30.5f; + public override float OtherValue { get; } = 30f; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs new file mode 100644 index 00000000..c594fc78 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedIntTypeTest(LibRedIntTypeTest.IntTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = -2147483648 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] int '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2147483647' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING int) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS int) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":2147483647,"Value":2147483647}' (Nullable = false) (Size = 44) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class IntTypeFixture : LibRedTypeFixture + { + public override int Value { get; } = int.MinValue; + public override int OtherValue { get; } = int.MaxValue; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs new file mode 100644 index 00000000..b13160d7 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedLongTypeTest(LibRedLongTypeTest.LongTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = -9223372036854775808 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bigint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='9223372036854775807' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bigint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bigint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":9223372036854775807,"Value":9223372036854775807}' (Nullable = false) (Size = 62) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class LongTypeFixture : LibRedTypeFixture + { + public override long Value { get; } = long.MinValue; + public override long OtherValue { get; } = long.MaxValue; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs new file mode 100644 index 00000000..b0428aae --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedShortTypeTest(LibRedShortTypeTest.ShortTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = CINT(-32768) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] smallint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='32767' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING smallint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS smallint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":32767,"Value":32767}' (Nullable = false) (Size = 34) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ShortTypeFixture : LibRedTypeFixture + { + public override short Value { get; } = short.MinValue; + public override short OtherValue { get; } = short.MaxValue; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs new file mode 100644 index 00000000..e77c3bc0 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateOnlyTypeTest(LibRedDateOnlyTypeTest.DateTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T00:00:00.0000000' (DbType = Date) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = #2020-01-05# +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] date '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = Date) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING date) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS date) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03","Value":"2022-05-03"}' (Nullable = false) (Size = 48) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTypeFixture : LibRedTypeFixture + { + public override DateOnly Value { get; } = new(2020, 1, 5); + public override DateOnly OtherValue { get; } = new(2022, 5, 3); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs new file mode 100644 index 00000000..ee9de9af --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateTime2TypeTest(LibRedDateTime2TypeTest.DateTime2TypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = #2020-01-05 12:30:45# +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime2 '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetime2) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime2) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTime2TypeFixture : LibRedTypeFixture + { + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs new file mode 100644 index 00000000..7625ae0e --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs @@ -0,0 +1,237 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeOffsetTypeTest( + LibRedDateTimeOffsetTypeTest.DateTimeOffsetTypeFixture fixture, + ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T10:30:45.0000000Z' (DbType = DateTime) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = CDATE('2020-01-05 10:30:45') +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetimeoffset '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2020-01-05T09:30:45.0000000Z' (DbType = DateTime) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetimeoffset) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetimeoffset) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2020-01-05T12:30:45+03:00","Value":"2020-01-05T12:30:45+03:00"}' (Nullable = false) (Size = 78) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeOffsetTypeFixture : LibRedTypeFixture + { + public override DateTimeOffset Value { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(2)); + public override DateTimeOffset OtherValue { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(3)); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs new file mode 100644 index 00000000..7174b88c --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs @@ -0,0 +1,225 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeTypeTest(LibRedDateTimeTypeTest.DateTimeTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = #2020-01-05 12:30:45# +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeTypeFixture : LibRedTypeFixture + { + // The default mapping for .NET DateTime is datetime2; this tests the non-default (and discouraged) datetime type. + public override string StoreType + => "datetime"; + + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs new file mode 100644 index 00000000..0770a58a --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedTimeOnlyTypeTest(LibRedTimeOnlyTypeTest.TimeOnlyTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = TIMEVALUE('12:30:45') +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00.0000000","Value":"14:00:00.0000000"}' (Nullable = false) (Size = 60) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeOnlyTypeFixture : LibRedTypeFixture + { + public override TimeOnly Value { get; } = new(12, 30, 45); + public override TimeOnly OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs new file mode 100644 index 00000000..1631bb2b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedTimeSpanTypeTest(LibRedTimeSpanTypeTest.TimeSpanTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = TIMEVALUE('12:30:45') +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00","Value":"14:00:00"}' (Nullable = false) (Size = 44) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeSpanTypeFixture : LibRedTypeFixture + { + public override TimeSpan Value { get; } = new(12, 30, 45); + public override TimeSpan OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..02d7cf57 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,102 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.ComplexTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.ComplexTableSplitting; + +public class ComplexTableSplittingPrimitiveCollectionLibRedTest( + ComplexTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : ComplexTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs new file mode 100644 index 00000000..40fb22ff --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs @@ -0,0 +1,158 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System; +using System.Data.Common; +using System.Threading.Tasks; +using Xunit; +using Xunit.Sdk; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsBulkUpdateLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsBulkUpdateRelationalTestBase(fixture, testOutputHelper) +{ + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + // FK constraint failures + public override Task Delete_entity_with_associations() + => Assert.ThrowsAsync(base.Delete_entity_with_associations); + + public override Task Delete_required_associate() + => Assert.ThrowsAsync(base.Delete_required_associate); + + // SQL generation produces invalid object name for these scenarios + public override Task Delete_optional_associate() + => Assert.ThrowsAsync(base.Delete_optional_associate); + + public override Task Update_property_inside_associate() + => Assert.ThrowsAsync(base.Update_property_inside_associate); + + public override Task Update_property_inside_associate_with_special_chars() + => Assert.ThrowsAsync(base.Update_property_inside_associate_with_special_chars); + + public override Task Update_property_on_projected_associate() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate); + + public override Task Update_property_on_projected_associate_with_OrderBy_Skip() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate_with_OrderBy_Skip); + + public override Task Update_multiple_properties_inside_same_associate() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_same_associate); + + public override Task Update_primitive_collection_to_constant() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_constant); + + public override Task Update_primitive_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_parameter); + + // Translation not yet supported for navigation-mapped associations + public override Task Update_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_parameter); + + public override Task Update_associate_to_inline() + => Assert.ThrowsAsync(base.Update_associate_to_inline); + + public override Task Update_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_inline_with_lambda); + + public override Task Update_associate_to_another_associate() + => Assert.ThrowsAsync(base.Update_associate_to_another_associate); + + public override Task Update_associate_to_null() + => Assert.ThrowsAsync(base.Update_associate_to_null); + + public override Task Update_associate_to_null_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_null_with_lambda); + + public override Task Update_associate_to_null_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_null_parameter); + + public override Task Update_nested_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_associate_to_parameter); + + public override Task Update_nested_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_associate_to_inline_with_lambda); + + public override Task Update_nested_associate_to_another_nested_associate() + => Assert.ThrowsAsync(base.Update_nested_associate_to_another_nested_associate); + + public override Task Update_nested_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_collection_to_parameter); + + public override Task Update_nested_collection_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_collection_to_inline_with_lambda); + + public override Task Update_nested_collection_to_another_nested_collection() + => Assert.ThrowsAsync(base.Update_nested_collection_to_another_nested_collection); + + public override Task Update_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_collection_to_parameter); + + public override Task Update_collection_referencing_the_original_collection() + => Assert.ThrowsAsync(base.Update_collection_referencing_the_original_collection); + + public override Task Update_primitive_collection_to_another_collection() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_another_collection); + + public override Task Update_inside_structural_collection() + => Assert.ThrowsAsync(base.Update_inside_structural_collection); + + public override Task Update_multiple_properties_inside_associates_and_on_entity_type() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_associates_and_on_entity_type); + + public override Task Update_multiple_projected_associates_via_anonymous_type() + => Assert.ThrowsAsync(base.Update_multiple_projected_associates_via_anonymous_type); + + public override async Task Update_property_inside_nested_associate() + { + await base.Update_property_inside_nested_associate(); + + AssertExecuteUpdateSql( + """ +@p='foo_updated' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [n] +SET [n].[String] = @p +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +"""); + } + + public override async Task Update_associate_with_null_required_property() + { + await base.Update_associate_with_null_required_property(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_required_nested_associate_to_null() + { + await base.Update_required_nested_associate_to_null(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_inside_primitive_collection() + { + await base.Update_inside_primitive_collection(); + + AssertExecuteUpdateSql( + """ +@p='99' + +SET NOCOUNT OFF; +UPDATE [a0] +SET [a0].[Ints] = JSON_MODIFY([a0].[Ints], '$[1]', @p) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [AssociateType] AS [a0] ON [r].[RequiredAssociateId] = [a0].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) >= 2 +"""); + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..681069c7 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsPrimitiveCollectionLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE CAST(JSON_VALUE([a].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[OptionalNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a0].[RequiredNestedAssociateId] = [n1].[Id] +LEFT JOIN [NestedAssociateType] AS [n2] ON [a].[OptionalNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([n].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..3f2c5201 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedNavigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.OwnedNavigations; + +public class OwnedNavigationsPrimitiveCollectionLibRedTest(OwnedNavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : OwnedNavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r0].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r0].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r1].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..7636c3a1 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,152 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.OwnedTableSplitting; + +public class OwnedTableSplittingPrimitiveCollectionLibRedTest( + OwnedTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : OwnedTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r2].[AssociateTypeRootEntityId], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r0].[RootEntityId], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r1].[AssociateTypeRootEntityId], [r1].[AssociateTypeId], [r1].[Id] AS [Id0], [r1].[Int] AS [Int0], [r1].[Ints] AS [Ints0], [r1].[Name] AS [Name0], [r1].[String] AS [String0], [r0].[OptionalNestedAssociate_Id], [r0].[OptionalNestedAssociate_Int], [r0].[OptionalNestedAssociate_Ints], [r0].[OptionalNestedAssociate_Name], [r0].[OptionalNestedAssociate_String], [r0].[RequiredNestedAssociate_Id], [r0].[RequiredNestedAssociate_Int], [r0].[RequiredNestedAssociate_Ints], [r0].[RequiredNestedAssociate_Name], [r0].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r0] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] AND [r0].[Id] = [r1].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r2] ON [r].[Id] = [r2].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r2].[AssociateTypeRootEntityId], [r2].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..1fe2e80e --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedFixture : TPCInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..36042a6c --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedTest(TPCInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [u].[ParentComplexType] +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([u].[ParentComplexType], '$.Nested') +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..7426d645 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,175 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceTableSplittingQueryLibRedTest(TPCInheritanceQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..053b64e9 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedFixture : TPHInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..2fd48f9f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,122 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedTest(TPHInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPHInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..6d002a9c --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,125 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceTableSplittingQueryLibRedTest( + TPHInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPHInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..ee7185bf --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedFixture : TPTInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..6f27ec8f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,145 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedTest(TPTInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPTInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..7da3e5c9 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,148 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceTableSplittingQueryLibRedTest( + TPTInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPTInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs new file mode 100644 index 00000000..70b6d612 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs @@ -0,0 +1,70 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Translations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Translations; + +public class JsonTranslationsLibRedTest : JsonTranslationsRelationalTestBase< + JsonTranslationsLibRedTest.JsonTranslationsQueryLibRedFixture> +{ + public JsonTranslationsLibRedTest(JsonTranslationsQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override async Task JsonPathExists_on_scalar_string_column() + { + await base.JsonPathExists_on_scalar_string_column(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonString], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_complex_property() + { + await base.JsonPathExists_on_complex_property(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonComplexType], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_owned_entity() + { + await base.JsonPathExists_on_owned_entity(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonOwnedType], N'$.OptionalInt') = 1 +"""); + } + + public class JsonTranslationsQueryLibRedFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + protected override string RemoveJsonProperty(string column, string property) + => $"JSON_MODIFY({column}, '$.{property}', NULL)"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); +} diff --git a/test/EFCore.LibRed.FunctionalTests/RuntimeMigrationLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/RuntimeMigrationLibRedTest.cs new file mode 100644 index 00000000..1ccd87fd --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/RuntimeMigrationLibRedTest.cs @@ -0,0 +1,20 @@ +using EntityFrameworkCore.LibRed.Design.Internal; +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Reflection; + +namespace EntityFrameworkCore.LibRed.FunctionalTests; + +public class RuntimeMigrationLibRedTest(RuntimeMigrationLibRedTest.RuntimeMigrationLibRedFixture fixture) + : RuntimeMigrationTestBase(fixture) +{ + protected override Assembly ProviderAssembly + => typeof(LibRedDesignTimeServices).Assembly; + + public class RuntimeMigrationLibRedFixture : RuntimeMigrationFixtureBase + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/LibRedTypeFixture.cs b/test/EFCore.LibRed.FunctionalTests/Types/LibRedTypeFixture.cs new file mode 100644 index 00000000..1a2f824a --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/LibRedTypeFixture.cs @@ -0,0 +1,14 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types; + +public abstract class LibRedTypeFixture : RelationalTypeFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + public virtual bool UsingJsonType + => false; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs new file mode 100644 index 00000000..b9c922a4 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedBoolTypeTest(LibRedBoolTypeTest.BoolTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(1 AS bit) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bit '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='False' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bit) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bit) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":false,"Value":false}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class BoolTypeFixture : LibRedTypeFixture + { + public override bool Value { get; } = true; + public override bool OtherValue { get; } = false; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs new file mode 100644 index 00000000..b2406f70 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs @@ -0,0 +1,220 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedByteArrayTypeTest(LibRedByteArrayTypeTest.ByteArrayTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 0x010203 +"""); + } + + // byte[].Equals() does reference equality, so the base test doesn't work for byte arrays + public override Task Primitive_collection_in_query() + => Task.CompletedTask; + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='0x04050607' (Size = 8000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with varbinary even on SQL Server 2025, as that type isn't supported + // (#36627). + // We also can't just wrap JSON_VALUE() with CAST(... AS varbinary(max)), as that would apply a SQL Server binary format + // conversion, and not base64. So we use OPENJSON which does perform base64 conversion. + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +OUTER APPLY OPENJSON([j].[JsonContainer]) WITH ([Value] varbinary(max) '$.Value') AS [v] +WHERE [v].[Value] = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"BAUGBw==","Value":"BAUGBw=="}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteArrayTypeFixture : LibRedTypeFixture + { + public override byte[] Value { get; } = [1, 2, 3]; + public override byte[] OtherValue { get; } = [4, 5, 6, 7]; + + public override Func Comparer { get; } = (a, b) => a.SequenceEqual(b); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs new file mode 100644 index 00000000..d6b2ec93 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs @@ -0,0 +1,227 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedGuidTypeTest(LibRedGuidTypeTest.GuidTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '8f7331d6-cde9-44fb-8611-81fff686f280' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] uniqueidentifier '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='ae192c36-9004-49b2-b785-8be10d169627' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with uniqueidentifier even on SQL Server 2025, as that type isn't + // supported (#36627). + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS uniqueidentifier) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"ae192c36-9004-49b2-b785-8be10d169627","Value":"ae192c36-9004-49b2-b785-8be10d169627"}' (Nullable = false) (Size = 100) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class GuidTypeFixture : LibRedTypeFixture + { + public override Guid Value { get; } = new("8f7331d6-cde9-44fb-8611-81fff686f280"); + public override Guid OtherValue { get; } = new("ae192c36-9004-49b2-b785-8be10d169627"); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs new file mode 100644 index 00000000..ac522cdb --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedStringTypeTest(LibRedStringTypeTest.StringTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = N'foo' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] nvarchar(max) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='bar' (Size = 4000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING nvarchar(max)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value') = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"bar","Value":"bar"}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class StringTypeFixture : LibRedTypeFixture + { + public override string Value { get; } = "foo"; + public override string OtherValue { get; } = "bar"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs new file mode 100644 index 00000000..b5b10381 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedByteTypeTest(LibRedByteTypeTest.ByteTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(0 AS tinyint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] tinyint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='255' (Size = 1) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING tinyint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS tinyint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":255,"Value":255}' (Nullable = false) (Size = 30) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteTypeFixture : LibRedTypeFixture + { + public override byte Value { get; } = byte.MinValue; + public override byte OtherValue { get; } = byte.MaxValue; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs new file mode 100644 index 00000000..de486a8f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedDecimalTypeTest(LibRedDecimalTypeTest.DecimalTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] decimal(18,2) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' (Precision = 18) (Scale = 2) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING decimal(18,2)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS decimal(18,2)) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DecimalTypeFixture : LibRedTypeFixture + { + public override decimal Value { get; } = 30.5m; + public override decimal OtherValue { get; } = 30m; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs new file mode 100644 index 00000000..7e1925ef --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedDoubleTypeTest(LibRedDoubleTypeTest.DoubleTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5E0 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] float '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING float) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS float) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DoubleTypeFixture : LibRedTypeFixture + { + public override double Value { get; } = 30.5d; + public override double OtherValue { get; } = 30d; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs new file mode 100644 index 00000000..ecea4266 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedFloatTypeTest(LibRedFloatTypeTest.FloatTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(30.5 AS real) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] real '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING real) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS real) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class FloatTypeFixture : LibRedTypeFixture + { + public override float Value { get; } = 30.5f; + public override float OtherValue { get; } = 30f; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs new file mode 100644 index 00000000..c6f8d23f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedIntTypeTest(LibRedIntTypeTest.IntTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = -2147483648 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] int '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2147483647' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING int) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS int) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":2147483647,"Value":2147483647}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class IntTypeFixture : LibRedTypeFixture + { + public override int Value { get; } = int.MinValue; + public override int OtherValue { get; } = int.MaxValue; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs new file mode 100644 index 00000000..495c4ebb --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedLongTypeTest(LibRedLongTypeTest.LongTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-9223372036854775808 AS bigint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bigint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='9223372036854775807' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bigint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bigint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":9223372036854775807,"Value":9223372036854775807}' (Nullable = false) (Size = 62) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class LongTypeFixture : LibRedTypeFixture + { + public override long Value { get; } = long.MinValue; + public override long OtherValue { get; } = long.MaxValue; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs new file mode 100644 index 00000000..a9861aad --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedShortTypeTest(LibRedShortTypeTest.ShortTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-32768 AS smallint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] smallint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='32767' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING smallint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS smallint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":32767,"Value":32767}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ShortTypeFixture : LibRedTypeFixture + { + public override short Value { get; } = short.MinValue; + public override short OtherValue { get; } = short.MaxValue; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs new file mode 100644 index 00000000..d71b7a1a --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateOnlyTypeTest(LibRedDateOnlyTypeTest.DateTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] date '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='05/03/2022' (DbType = Date) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING date) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS date) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03","Value":"2022-05-03"}' (Nullable = false) (Size = 48) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTypeFixture : LibRedTypeFixture + { + public override DateOnly Value { get; } = new(2020, 1, 5); + public override DateOnly OtherValue { get; } = new(2022, 5, 3); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs new file mode 100644 index 00000000..48a4cb7c --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateTime2TypeTest(LibRedDateTime2TypeTest.DateTime2TypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime2 '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetime2) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime2) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTime2TypeFixture : LibRedTypeFixture + { + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs new file mode 100644 index 00000000..210f8a4b --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs @@ -0,0 +1,241 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeOffsetTypeTest( + LibRedDateTimeOffsetTypeTest.DateTimeOffsetTypeFixture fixture, + ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000+02:00' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetimeoffset '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2020-01-05T12:30:45.0000000+03:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetimeoffset) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetimeoffset) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2020-01-05T12:30:45+03:00","Value":"2020-01-05T12:30:45+03:00"}' (Nullable = false) (Size = 78) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeOffsetTypeFixture : LibRedTypeFixture + { + public override DateTimeOffset Value { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(2)); + public override DateTimeOffset OtherValue { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(3)); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs new file mode 100644 index 00000000..608c9eed --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs @@ -0,0 +1,229 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeTypeTest(LibRedDateTimeTypeTest.DateTimeTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeTypeFixture : LibRedTypeFixture + { + // The default mapping for .NET DateTime is datetime2; this tests the non-default (and discouraged) datetime type. + public override string StoreType + => "datetime"; + + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs new file mode 100644 index 00000000..150c7a54 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedTimeOnlyTypeTest(LibRedTimeOnlyTypeTest.TimeOnlyTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00' (DbType = Time) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00.0000000","Value":"14:00:00.0000000"}' (Nullable = false) (Size = 60) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeOnlyTypeFixture : LibRedTypeFixture + { + public override TimeOnly Value { get; } = new(12, 30, 45); + public override TimeOnly OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs new file mode 100644 index 00000000..e5b670bd --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedTimeSpanTypeTest(LibRedTimeSpanTypeTest.TimeSpanTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00","Value":"14:00:00"}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeSpanTypeFixture : LibRedTypeFixture + { + public override TimeSpan Value { get; } = new(12, 30, 45); + public override TimeSpan OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} From 7fb504b93cfc3202784cff7044e723e74d15c55a Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 26 Oct 2026 00:52:43 +0800 Subject: [PATCH 06/27] Bump the version to 11.0.0-beta.1 Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- CLAUDE.md | 2 +- Version.props | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f5534a1d..5ce94de0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ It is kept in sync with `CLAUDE.md`; if you change guidance in one, check whethe EntityFrameworkCore.Jet is an EF Core provider for Microsoft Jet/ACE databases (Microsoft Access `.mdb`/`.accdb` files). The **Jet** provider runs **Windows only** and bridges EF Core to the Access database engine via either ODBC or OLE DB. Alongside it, **LibRed** (also in this repo, on `master`) is a from-scratch managed engine that reads/writes the file format directly and is **cross-platform** — see the LibRed section below. -Current version: `11.0.0-alpha.4` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC2 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. +Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC2 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. `LibRed.Core`, `LibRed.Sql`, `LibRed.Engine` and `LibRed.Ado` are the exception: they multi-target `$(LibRedTargetFrameworks)` = `net10.0;net11.0`, since none of them depends on an EF Core package. `LibRed.EFCore` diff --git a/CLAUDE.md b/CLAUDE.md index 3774a127..bc94356e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co EntityFrameworkCore.Jet is an EF Core provider for Microsoft Jet/ACE databases (Microsoft Access `.mdb`/`.accdb` files). The **Jet** provider runs **Windows only** and bridges EF Core to the Access database engine via either ODBC or OLE DB. Alongside it, **LibRed** (also in this repo, on `master`) is a from-scratch managed engine that reads/writes the file format directly and is **cross-platform** — see the LibRed section below. -Current version: `11.0.0-alpha.4` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC2 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. +Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC2 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. **One exception to `net11.0`:** `LibRed.Core`, `LibRed.Sql`, `LibRed.Engine` and `LibRed.Ado` multi-target `$(LibRedTargetFrameworks)` = `net10.0;net11.0`, because none of them depends on an EF Core package. `LibRed.EFCore` diff --git a/Version.props b/Version.props index 6b69c475..7b97835a 100644 --- a/Version.props +++ b/Version.props @@ -16,8 +16,8 @@ correctly. --> 11.0.0 - alpha - 4 + beta + 1 + + diff --git a/src/LibRed/LibRed.Core/Pages/DataPage.cs b/src/LibRed/LibRed.Core/Pages/DataPage.cs index 9ae17236..5cc8945c 100644 --- a/src/LibRed/LibRed.Core/Pages/DataPage.cs +++ b/src/LibRed/LibRed.Core/Pages/DataPage.cs @@ -288,10 +288,14 @@ private static void ValidateSlot(PageBuffer buffer, int index, int offset, int p /// masked out of and so can exceed the page; rows are packed from the page end /// backward, so they must also never increase. RowInserter's in-place repackers re-derived this /// arithmetic without the checks, which on a corrupt directory produced an out-of-range exception from a - /// half-repacked page rather than a diagnosis. + /// half-repacked page rather than a diagnosis. The previous boundary is checked too: a directory walk has + /// already validated it, but reads it straight from the neighbouring slot. internal static void ValidateSlot( int pageNumber, int bufferLength, int index, int offset, int previousEnd, int directoryEnd) { + if (previousEnd > bufferLength) + throw new InvalidDataException( + $"Data page {pageNumber} row slot {index - 1} has offset {previousEnd}, past the page end {bufferLength}."); if (offset < directoryEnd || offset > bufferLength) throw new InvalidDataException( $"Data page {pageNumber} row slot {index} has offset {offset}, outside the row heap " + diff --git a/src/LibRed/LibRed.Core/Storage/BitmapBits.cs b/src/LibRed/LibRed.Core/Storage/BitmapBits.cs index f37ce293..ad0664cd 100644 --- a/src/LibRed/LibRed.Core/Storage/BitmapBits.cs +++ b/src/LibRed/LibRed.Core/Storage/BitmapBits.cs @@ -70,6 +70,10 @@ public static void AppendPages( for (int bit = NextSetBit(bitmap, 0); bit >= 0; bit = NextSetBit(bitmap, bit + 1)) { long page = (long)basePage + bit; + // Keeping every bit keeps pages past the file's end, never a page no file can have: a negative one + // would be taken for a bit index below the bitmap's first byte. + if (page is < 0 or > int.MaxValue) + throw new InvalidDataException($"{what} names page {page}, which no file can hold."); if (rejectBeyond is { } pageCount && (page <= 1 || page >= pageCount)) throw new InvalidDataException( $"{what} names page {page}, outside the file's 2..{pageCount - 1} range."); diff --git a/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs b/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs index 138edd2b..5eff702f 100644 --- a/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs +++ b/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs @@ -150,6 +150,9 @@ private static byte[] EncodePayload(ColumnDef column, JetDataType type, object v $"Calculated column '{column.Name}' contains an invalid expression: its descriptor lacks the flag that " + "lets the expression be evaluated."); + // The width first: a slot too short to be an envelope is damage, and its first four bytes are no status. + ReadOnlySpan payload = Payload(envelope, column); + // A failed expression is cached as its VBA error number with no payload, so it is NOT a Null even // though it has a Null's empty payload -- and reading it as one is a silent wrong answer, on a value // neither engine re-derives. ACE will not hand back such a row at all. @@ -158,7 +161,6 @@ private static byte[] EncodePayload(ColumnDef column, JetDataType type, object v $"Calculated column '{column.Name}' holds a cached error, not a value: " + $"{VbaErrorText(error)}. Its expression is '{column.CalculatedExpression ?? "(unknown)"}'."); - ReadOnlySpan payload = Payload(envelope, column); JetDataType type = StoredType(column, payload.Length); // A zero-length payload is a Null result -- EXCEPT for text, where it is the empty string. The two @@ -172,10 +174,9 @@ private static byte[] EncodePayload(ColumnDef column, JetDataType type, object v } /// The envelope's leading status: 0 when the expression produced a value, otherwise the VBA - /// runtime error number it raised. A short envelope reads as 0 — a truncated slot is the width check's - /// business, not this one's. + /// runtime error number it raised. Read only after has checked the width. private static uint Status(ReadOnlySpan envelope) => - envelope.Length >= StatusSize ? BinaryPrimitives.ReadUInt32LittleEndian(envelope[..StatusSize]) : 0; + BinaryPrimitives.ReadUInt32LittleEndian(envelope[..StatusSize]); /// Names the VBA errors a calculated expression can actually raise, so the message says what /// went wrong rather than quoting a number. Measured: CDbl(Null) caches 94 and CDbl('hello') diff --git a/src/LibRed/LibRed.Core/Storage/IndexTree.cs b/src/LibRed/LibRed.Core/Storage/IndexTree.cs index 96ffb12a..bc34a7c9 100644 --- a/src/LibRed/LibRed.Core/Storage/IndexTree.cs +++ b/src/LibRed/LibRed.Core/Storage/IndexTree.cs @@ -177,8 +177,10 @@ public void RemoveEntry(IndexDef index, object?[] values, RowId rowId) int idx = LowerBound(entries, key); while (idx < entries.Count && CompareBytes(entries[idx].Key, key) == 0 && entries[idx].Trailer != pointer) idx++; + // The key is built from the row's own stored values, so a missing entry is an index that disagrees with its + // table: damage, which ACE refuses too ("The search key was not found in any record.", measured). if (idx == entries.Count || entries[idx].Trailer != pointer || CompareBytes(entries[idx].Key, key) != 0) - throw new InvalidOperationException( + throw new InvalidDataException( $"Index '{index.Name}': entry for row {rowId.Page}:{rowId.Row} was not found on leaf {leafPage}."); entries.RemoveAt(idx); diff --git a/src/LibRed/LibRed.Core/Storage/PageAllocator.cs b/src/LibRed/LibRed.Core/Storage/PageAllocator.cs index 92569a9f..8dc6ed2b 100644 --- a/src/LibRed/LibRed.Core/Storage/PageAllocator.cs +++ b/src/LibRed/LibRed.Core/Storage/PageAllocator.cs @@ -520,7 +520,9 @@ private void SizeReleasedMap(SortedSet pages) int start = UsageMap.StartPage(released.Record, format); int lowest = pages.Min, highest = pages.Max; int Covering(int from) => headerSize + UsageMap.InlineBitmapBytes(format, highest - from + 1); - if (lowest >= start && highest < start + (released.Slot.Length - headerSize) * 8) return; + // A map starting below page 0 is left as it was, and the pages are freed all the same: ACE's close does + // (measured, start -2,147,483,648). + if (start < 0 || lowest >= start && highest < start + (released.Slot.Length - headerSize) * 8) return; var holder = new DataPage(); holder.Read(new PageBuffer(released.Page, released.PageNumber), format); @@ -876,6 +878,11 @@ private static void ValidateReusablePage(int page, string source, MapRecord free /// against two ACE handles. private void EnsurePhysicalAllocation(int page) { + // A page past the largest file is in no database: ACE refuses to allocate it and leaves the file as it was + // (measured), where growing towards it would buffer pages up to the 2 GiB limit before WritePage refused one. + if (page > _channel.PageCount && page >= _channel.MaxPageCount) + throw new InvalidDataException( + $"The global free map selected page {page}, past the largest file of {_channel.MaxPageCount} pages."); while (_channel.PageCount < page) Append(); if (page < _channel.PageCount) return; int allocated = Append(); diff --git a/src/LibRed/LibRed.Core/Storage/RowInserter.cs b/src/LibRed/LibRed.Core/Storage/RowInserter.cs index 682081ad..a9b9429e 100644 --- a/src/LibRed/LibRed.Core/Storage/RowInserter.cs +++ b/src/LibRed/LibRed.Core/Storage/RowInserter.cs @@ -1335,7 +1335,12 @@ private void UpdateTdefCounters(JetFormatBase format, byte[] tdef, object?[] val // a UI-authored Random AutoNumber reads last-value 0). Advancing it would be meaningless (random ids // don't form a monotone sequence) and diverge from Access's on-disk state. if (column.IsRandomAutoNumber) continue; - int assigned = Convert.ToInt32(value, CultureInfo.InvariantCulture); + // The counter is a value's first four bytes. On a Text column that carries the AutoNumber flag — a + // damaged descriptor — ACE takes them from the UTF-16 text, zero-padded (measured: "Street" sets 0x14 to + // 0x00740053, "A" to 65). + int assigned = value is string text + ? (text.Length > 0 ? text[0] : 0) | (text.Length > 1 ? text[1] << 16 : 0) + : Convert.ToInt32(value, CultureInfo.InvariantCulture); int highWater = TableDefinition.ReadLastAutoNumber(tdef, format); // An id this insert *generated* always becomes the new high-water: it came from 0x14 + increment, // so it is by construction the next value in the sequence. That includes the wrap past diff --git a/src/LibRed/docs/format/page-02a-tdef.md b/src/LibRed/docs/format/page-02a-tdef.md index aa7479c9..006ad28e 100644 --- a/src/LibRed/docs/format/page-02a-tdef.md +++ b/src/LibRed/docs/format/page-02a-tdef.md @@ -94,6 +94,13 @@ > it pins `0x14` at `int.MaxValue` forever, so every later insert reissues `int.MinValue` and the table is > wedged — for ACE too, since the damage is the on-disk `0x14`. LibRed therefore applies its monotone guard > (the deliberate KB 884185 immunity) **only to caller-supplied explicit ids**; see `RowInserter`. +> +> **The counter is the first four bytes of the value (verified vs ACE).** A Text column whose descriptor carries +> the AutoNumber flag `0x04` (a damaged file) still opens, reads and takes INSERTs and DELETEs; an UPDATE of the +> column is refused as not updateable. An explicit text value sets `0x14` to the value's first four bytes as UTF-16LE, +> zero-padded: `'Street'` → `0x00740053`, `'500'` → `0x00300035`, `'A'` → `65`. A generated id goes the other way — +> with the flag byte `0x06` the id's four bytes are stored as two characters (`0x00740054` → `'Tt'`); with `0xEE` +> (`0x40` set as well) ACE stores `'\x01\0'` and resets `0x14` to `1`. LibRed matches the explicit case only. > **Reader/writer count guardrails.** LibRed validates the documented 255-column and 32-real-index > limits before allocating count-sized structures, rejects negative logical/real index counts, and checks diff --git a/src/LibRed/docs/format/page-02b-columns.md b/src/LibRed/docs/format/page-02b-columns.md index 2a6e11ef..8add3852 100644 --- a/src/LibRed/docs/format/page-02b-columns.md +++ b/src/LibRed/docs/format/page-02b-columns.md @@ -41,14 +41,21 @@ normally, but a compact drops the column, every column after it and every row of > computed and stored, on an insert and on an update of a column it reads, while a Text or Memo one refuses both > (*"Error evaluating CHECK constraint."*). An update that touches none of its inputs, and a delete, go through > either way. A column with `0x40` and no expression at all fails before that, the table refusing to open -> (*"Property not found"*), and a compact drops it. `0x80` alone does nothing: the column is an ordinary one, and +> (*"Property not found"*), and a compact drops it — fixed-length or variable, everything that loads that table +> fails so, its column schema included, while the table list and the other tables still read. On a **catalog** +> table it depends which: `0x40` on any `MSysObjects` column, fixed or variable, and the database itself will not +> open (*"Invalid database object reference."*); on `MSysRelationships` the foreign-key list fails *"Property not +> found"* as a user table's reads do; on `MSysQueries` the database opens and lists no views at all. `0x80` alone +> does nothing: the column is an ordinary one, and > the bit goes at the next TDEF rewrite. A broken expression does not clear `0x80` — after `DROP COLUMN` of a > column it reads, the flags stay `0xC0` and the error comes from the expression itself. Extended bit `0x02` is > ignored and kept, through a rewrite and a compact alike. > > LibRed reads `0x40` as calculated and writes `0xC0`, as ACE does, and over `0x40` alone reads, writes, updates > and deletes as ACE does (`ColumnDef.EvaluatesExpression`). An update or delete never reads a calculated -> result, which is also what lets it rewrite a row whose result is a cached error. +> result, which is also what lets it rewrite a row whose result is a cached error. A calculated column with no +> `Expression` property refuses its table's definition, and one in `MSysObjects` refuses the catalog, both as +> `InvalidDataException`; a damaged `MSysQueries` refuses too, where ACE lists no views. > > **Extended flags beyond `0x01`/`0xC0` belong to the complex columns (verified where set).** `0x10` is set on > exactly the six attachment value columns — `FileData`, `FileFlags`, `FileName`, `FileTimeStamp`, `FileType`, @@ -355,6 +362,16 @@ column's rank among the variable columns ordered by ascending id. > read the dropped column's value). Why the gap is left, and what it means for writing a row rather than > reading one, are [§3.1](page-02a-tdef.md#31-header) and [§5](page-01-data-and-rows.md) respectively. +> **Two live columns naming one slot.** ACE does not check that variable indexes are distinct (verified on +> Northwind's `Customers` with `City`'s index set to `CompanyName`'s, 0): the table opens and reads, and `City` +> reads the company name, cut to `City`'s declared 15 characters in a `SELECT`. A write of `City` with that +> value is refused as too large for the field, an update of another column succeeds, and an insert writes both +> columns through the one slot, the later value winning. An index on `City` still holds each row under its +> real city, so a write that has to move or remove that entry fails as the index section's missing-entry case +> ([§10.4a](page-03-04-index-btree.md#104a-entry-removal--a-leaf-is-rewritten-not-repacked)). LibRed opens +> and reads the table and refuses the same writes, but returns `City` whole (19 characters); whether ACE's cut +> is the engine's or the OLE DB column binding's is not established. + #### Declared width limits Two limits bind a declaration, both enforced by ACE when it **opens the file**, so writing past either diff --git a/src/LibRed/docs/format/page-03-04-index-btree.md b/src/LibRed/docs/format/page-03-04-index-btree.md index 15be6904..513c460c 100644 --- a/src/LibRed/docs/format/page-03-04-index-btree.md +++ b/src/LibRed/docs/format/page-03-04-index-btree.md @@ -971,6 +971,13 @@ packing: where the prefix is longer than the key, there are no key bytes left to Both engines then agree byte for byte: LibRed touches no page ACE does not (verified). +> **An entry the row says is there, and is not.** The entry to remove is found by the key the row's stored +> values encode to. When the index holds the row under another key — the file's index and table disagree — +> ACE refuses the `UPDATE` that would move the entry, and the `DELETE` that would remove it, with *"The search +> key was not found in any record."* and changes nothing (verified, on a `Customers` row whose `City` reads +> another column's slot, §3 of [page-02b](page-02b-columns.md)). LibRed refuses both with +> `InvalidDataException` and rolls the statement back. + ### 10.4d A leaf the removal empties leaves the tree An underfull leaf is left alone (§10.4a), but a leaf whose **last** entry is removed is taken out of the tree diff --git a/src/LibRed/docs/format/page-05-usage-maps.md b/src/LibRed/docs/format/page-05-usage-maps.md index 1c31bad4..97ae795e 100644 --- a/src/LibRed/docs/format/page-05-usage-maps.md +++ b/src/LibRed/docs/format/page-05-usage-maps.md @@ -234,6 +234,40 @@ the opening user's commit slot at close, and every later open fails with *"Unrec A far larger page number is refused on the first open — from page 524,289 exactly, as measured on `0x1C`. Only the page is checked on open — any row byte passes — but a `0x18` naming a record that is not a usage map (page 0, a TDEF page, an ordinary data page) fails at the first allocation and damages the database. +Aimed at a long-value row instead — row 0 of a 4,076-byte value, whose bytes read as an inline map starting at +page 352,321,631 — the database opens and reads, and every statement needing a page fails *"Cannot open database +''"* with the file left as it was: no page added, the long value untouched. An `INSERT` that had drawn its +AutoNumber keeps it burned (verified). LibRed refuses to grow the file to any page past the 2 GiB limit, which +refuses this one at the same point. + +**ACE does not look at the page the free map gives it (verified).** A `0x18` naming a table's own owned-pages +map makes that table's pages free, and so does the page's bit set in the real free map; either way ACE allocates +the page and writes over it. That held for a user table's page, a system table's, a page of the table the +statement itself reads and writes, and one the connection had just scanned — a `CREATE TABLE` writes its +definition there, an `INSERT` needing a long-value page writes one, and the rows on it are lost to a scan while +`COUNT(*)` still answers from the TDEF's row count. + +Only some statements fail, and only on some tables' pages: + +- **`CREATE TABLE`** fails when it took a page of `MSysObjects` or `MSysACEs` — the two tables it inserts rows + into — with the write-conflict error ("…you and another user are attempting to change the same data at the + same time"). The page and the file are left intact. Taking a page of `MSysQueries` or `MSysRelationships`, + which it writes nothing to, succeeds. +- **An `INSERT` writing a long value** fails with *"Unrecognized database format"* when the page it took is the + `MSysObjects` page holding its own table's row, or the one holding the database's and containers' rows (with + `MSysDb`). It fails after drawing the AutoNumber and before writing the row, leaves the page as it was, and + the file does not open again. Reading the table or its columns, or inserting a short row into it, on the same + connection first changes nothing. The same `INSERT` taking another `MSysObjects` page succeeds and writes its + long value over the catalog rows there, as does one taking a page of `MSysACEs` or `MSysRelationships`; so does + an `INSERT` that needs only data pages, onto any catalog page, its own table's row's included. Which of the + first page's rows the long-value write goes back to is not established. + +So ACE has no check that keeps a live page out of allocation; a statement fails when it goes back to the table +whose page it took. LibRed allocates the same way. Where its statement goes back to such a page through a read +that checks the page — `CREATE TABLE` inserting its catalog row on the `MSysObjects` page it has just made a +definition — it refuses with `InvalidDataException` and rolls back, leaving the file intact as ACE does. Which +page each engine takes, and what each goes back to, differ, so the two do not fail on the same cases: the +`INSERT` that takes an `MSysObjects` page succeeds in LibRed and leaves the catalog damaged. **Freed pages are released at close, through the released-pages map.** Most pages freed during a session are not reusable on the same connection: later allocations in that session grow the file instead, and the free map on @@ -279,6 +313,10 @@ An inline record that already covers them stays as it is. Otherwise, in order of end and the vacated bytes are not cleared, so the long record's bitmap stays on the page below the new one. +An inline record whose start page is below 0 is not sized at all: with start page -2,147,483,648 and no bits set, +releasing three pages and closing leaves the record as it was and merges the pages into the free map exactly as +on the undamaged file (verified). + A map already in reference form gains a bitmap page, allocated the same way, for each range holding a released page that it has none for — a released table-definition page among the free pages is taken like any other, its type becoming `0x0105`. The merge then clears every bitmap page, each keeping its 4-byte header. diff --git a/src/LibRed/docs/format/system-catalog.md b/src/LibRed/docs/format/system-catalog.md index 9555d65e..2f0215db 100644 --- a/src/LibRed/docs/format/system-catalog.md +++ b/src/LibRed/docs/format/system-catalog.md @@ -51,6 +51,13 @@ The last column lists what a row of that kind *can* carry, not what every one does: a query or relationship written by ACE or LibRed leaves `LvProp` null (below), where Access fills it. + > **A table's row with a null `Id`, `Name` or `Flags`** (measured, by clearing the column's null-bitmap bit). + > The database still opens. A null **`Flags`** is no flags: the table reads as usual, and `MSysQueries`, its + > system bit gone, is listed as a `TABLE`. A null **`Id`** leaves the table listed but unreadable — *"Unrecognized + > database format"* — and on `MSysQueries` leaves no views at all. A null **`Name`** fails the table list + > (`E_FAIL`). LibRed reads a null `Flags` as `0` and refuses a table whose row has no `Id` or `Name` as + > `InvalidDataException`. + > **A name is unique within its container, and only there.** That is the rule the unique `(ParentId, Name)` > index states, and the one ACE applies (verified, case-insensitively): a new table (`CREATE TABLE`, > `SELECT … INTO`, a rename) or query (`CREATE VIEW` / `CREATE PROCEDURE`) is refused when a table, query or diff --git a/test/LibRed.Core.Fuzz/LibRed.Core.Fuzz.csproj b/test/LibRed.Core.Fuzz/LibRed.Core.Fuzz.csproj new file mode 100644 index 00000000..998e1c49 --- /dev/null +++ b/test/LibRed.Core.Fuzz/LibRed.Core.Fuzz.csproj @@ -0,0 +1,43 @@ + + + + Exe + $(JetTargetFramework) + LibRed.Core.Fuzz + enable + enable + false + AnyCPU;x86;x64 + + true + $(MSBuildThisFileDirectory)..\..\Key.snk + + + + + + + + + + + + + + + + Data\Northwind.accdb + PreserveNewest + + + Data\EncryptedTest.accdb + PreserveNewest + + + + diff --git a/test/LibRed.Core.Fuzz/Program.cs b/test/LibRed.Core.Fuzz/Program.cs new file mode 100644 index 00000000..0e4c3082 --- /dev/null +++ b/test/LibRed.Core.Fuzz/Program.cs @@ -0,0 +1,162 @@ +using System.Buffers.Binary; +using System.Runtime.ExceptionServices; +using LibRed.Catalog; +using LibRed.Formats; +using LibRed.Tests.Shared; +using SharpFuzz; + +namespace LibRed.Core.Fuzz; + +// Coverage-guided fuzzing of LibRed.Core with SharpFuzz + libFuzzer. See README.md for how to run it. +// +// Every target holds LibRed to the contract MalformedFile states: a damaged input may throw +// InvalidDataException, NotSupportedException or UnauthorizedAccessException and nothing else. Anything else +// escaping a target is a crash to libFuzzer. Hangs and runaway allocations are libFuzzer's -timeout and +// -rss_limit_mb, which is the half of the problem the fixed-seed sweep in LibRed.Core.Tests cannot see. +// +// Two ways in: +// LIBRED_FUZZ_TARGET=, run under libfuzzer-dotnet — fuzz (libfuzzer-dotnet passes one argument, +// the dll, so the target travels in the env) +// dotnet LibRed.Core.Fuzz.dll replay — run saved inputs (a crash, a corpus) once +// each, uninstrumented, and report any leak +internal static class Program +{ + private static int Main(string[] args) + { + if (args is ["replay", string replayTarget, string input]) + return Replay(Target(replayTarget), input); + + string? name = Environment.GetEnvironmentVariable("LIBRED_FUZZ_TARGET"); + if (name is null || args is ["replay", ..]) + { + Console.Error.WriteLine("Fuzz: set LIBRED_FUZZ_TARGET and run under libfuzzer-dotnet (see README.md)"); + Console.Error.WriteLine("Replay: LibRed.Core.Fuzz replay "); + Console.Error.WriteLine($"Targets: {string.Join(", ", Targets)}"); + return 2; + } + + Fuzzer.LibFuzzer.Run(Target(name)); + return 0; + } + + private static readonly string[] Targets = ["database", "writes", "properties", "namemap"]; + + private static ReadOnlySpanAction Target(string name) => name switch + { + "database" => new DatabaseTarget(write: false).Run, + "writes" => new DatabaseTarget(write: true).Run, + "properties" => Properties, + "namemap" => NameMapBlob, + _ => throw new ArgumentException($"Unknown target '{name}'. Targets: {string.Join(", ", Targets)}.", nameof(name)), + }; + + /// An LvProp property blob, as the catalog reads one for every table. + private static void Properties(ReadOnlySpan data) + { + try { PropertyBlob.Read(data); } + catch (Exception e) when (MalformedFile.IsExpected(e)) { } + } + + /// A name map, in both of its stored layouts: an MSysNameMap row and an LvProp + /// property. + private static void NameMapBlob(ReadOnlySpan data) + { + try { NameMap.ReadRow(data); } + catch (Exception e) when (MalformedFile.IsExpected(e)) { } + try { NameMap.ReadProperty(data); } + catch (Exception e) when (MalformedFile.IsExpected(e)) { } + } + + /// Runs each saved input through once and reports what leaks. + private static int Replay(ReadOnlySpanAction target, string input) + { + string[] files = Directory.Exists(input) ? Directory.GetFiles(input) : [input]; + int leaks = 0; + foreach (string file in files) + { + try { target(File.ReadAllBytes(file)); } + catch (Exception e) + { + leaks++; + Console.WriteLine($"LEAK {Path.GetFileName(file)}: {e}"); + } + } + Console.WriteLine($"{files.Length} inputs, {leaks} leaked"); + return leaks == 0 ? 0 : 1; + } +} + +/// +/// A whole database, damaged by the fuzz input and then walked as a caller would (MalformedFile.Exercise) — +/// read only, or with a row of each user table rewritten, deleted and inserted again on the way. +/// +/// +/// The input is not a file. A database is hundreds of pages and libfuzzer-dotnet carries at most 1 MiB, and +/// mutating a whole file spends nearly every mutation on row data. So the input is a patch list against one of +/// a fixed set of good seed databases: [seed][page u16][offset u16][byte]…, each field reduced modulo +/// what it indexes. Inputs stay a few bytes long, every one decodes to a database, and libFuzzer still learns +/// which patches reach new code. Unlike the sweep, page 0 and every offset are in range. +/// +internal sealed class DatabaseTarget +{ + private const int PatchSize = 5; + + private readonly bool _write; + private readonly string _directory; + private readonly string _path; + private (string Shape, byte[] Bytes, int PageSize, string? Password)[]? _seeds; + + public DatabaseTarget(bool write) + { + _write = write; + _directory = Path.Combine(Path.GetTempPath(), $"libred-fuzz-{Guid.NewGuid():N}"); + Directory.CreateDirectory(_directory); + // libFuzzer ends the process on a crash, which skips this; the folder is then left in %TEMP%. + AppDomain.CurrentDomain.ProcessExit += (_, _) => + { + try { Directory.Delete(_directory, recursive: true); } catch (IOException) { /* best effort */ } + }; + + // One path, rewritten every run. The page cache and lock registries are per path and released on the + // last close, so a run that leaves a handle open fails the next write — a leak worth seeing. + _path = Path.Combine(_directory, "input.accdb"); + } + + public void Run(ReadOnlySpan data) + { + if (data.Length == 0) return; + // Built on the first input, not in the constructor: authoring the seeds and detecting their page size + // run instrumented LibRed.Core code, and SharpFuzz's coverage map only exists once Fuzzer.LibFuzzer.Run + // has started — instrumented code called before that dereferences a null map. + _seeds ??= LoadSeeds(); + (_, byte[] clean, int pageSize, string? password) = _seeds[data[0] % _seeds.Length]; + + byte[] bytes = (byte[])clean.Clone(); + int pages = bytes.Length / pageSize; + for (int i = 1; i + PatchSize <= data.Length; i += PatchSize) + { + int page = BinaryPrimitives.ReadUInt16LittleEndian(data[i..]) % pages; + int offset = BinaryPrimitives.ReadUInt16LittleEndian(data[(i + 2)..]) % pageSize; + bytes[page * pageSize + offset] = data[i + 4]; + } + File.WriteAllBytes(_path, bytes); + + foreach ((_, Exception? leak) in MalformedFile.Exercise(_path, password, _write)) + if (leak is not null) + ExceptionDispatchInfo.Throw(leak); + } + + private (string Shape, byte[] Bytes, int PageSize, string? Password)[] LoadSeeds() + { + string data = Path.Combine(AppContext.BaseDirectory, "Data"); + var sources = MalformedFile.Sources(_directory, Path.Combine(data, "Northwind.accdb")) + .Select(s => (s.Shape, s.Path, Password: (string?)null)) + .Append(("encrypted", Path.Combine(data, "EncryptedTest.accdb"), "Test")); + + return [.. sources.Select(s => + { + byte[] bytes = File.ReadAllBytes(s.Item2); + return (s.Item1, bytes, JetFormatBase.Detect(new MemoryStream(bytes)).PageSize, s.Item3); + })]; + } +} diff --git a/test/LibRed.Core.Fuzz/README.md b/test/LibRed.Core.Fuzz/README.md new file mode 100644 index 00000000..e8fe2dbb --- /dev/null +++ b/test/LibRed.Core.Fuzz/README.md @@ -0,0 +1,83 @@ +# LibRed.Core.Fuzz + +Coverage-guided fuzzing of `LibRed.Core` with [SharpFuzz](https://github.com/Metalnem/sharpfuzz) and libFuzzer. +SharpFuzz rewrites `LibRed.Core.dll` to report the branches each input reaches; libFuzzer keeps the inputs that +reach new ones and mutates those. + +The contract is the one the fixed-seed sweep in `LibRed.Core.Tests` (`CorruptFileSweepProbeTests`) enforces, and +both read it from the same file, `test/LibRed.Shared/MalformedFile.cs`: damaged bytes may throw +`InvalidDataException`, `NotSupportedException` or `UnauthorizedAccessException`, and **anything else escaping is +a crash**. On top of that, libFuzzer reports what the sweep cannot see: a **hang** (`-timeout`, e.g. a page chain +that loops) and a **runaway allocation** (`-rss_limit_mb`, e.g. a length field taken at its word). + +The sweep stays the regression guard; this is the search. Nothing here runs in CI. + +## Targets + +| `LIBRED_FUZZ_TARGET` | Input | What it drives | +| --- | --- | --- | +| `database` | a patch list (below) | open, catalog, every table's rows, every index's entries — `MalformedFile.Exercise` | +| `writes` | a patch list (below) | the same walk opened for writing: in each user table still listed, the first of its first 32 rows the write accepts is also rewritten in place, deleted and inserted again, before its indexes are walked | +| `properties` | raw bytes | `PropertyBlob.Read`, the `LvProp` blob decoder | +| `namemap` | raw bytes | `NameMap.ReadRow` and `NameMap.ReadProperty` | + +**The `database` and `writes` input is not a file.** A database is hundreds of pages, libfuzzer-dotnet carries at most 1 MiB, +and mutating a whole file spends nearly every mutation on row data. Instead the input is +`[seed][page u16][offset u16][byte]…`, applied to one of six good databases built at startup: Northwind, the four +shapes `MalformedFile.Sources` authors (multi-page TDEF, long values, split index, altered columns), and the Agile +-encrypted fixture opened with its password. Every field is reduced modulo what it indexes, so every input decodes +to a database, page 0 included. + +`writes` holds the write paths to the same contract with one widening: a write may also refuse with +`InvalidOperationException`. Damage to a schema routinely makes a row's own values break it — a Null key, a value +past its column, a record past the page, a write-once column — and the write API refuses those as ACE does, so +treating them as leaks only buries the real findings: an out-of-range index, a null reference, an overflow, a hang. +The cost is that damage which surfaces as `InvalidOperationException` goes unflagged here. The two targets take +the same inputs, so `corpus\database` is a good starting corpus for `corpus\writes`. + +## Running it + +You need the SharpFuzz instrumenter and the libFuzzer driver. Both are third-party downloads, not restored by the +build: + +- `dotnet tool install --global SharpFuzz.CommandLine` +- **libfuzzer-dotnet** from — the Windows build is + `libfuzzer-dotnet-windows.exe`. On Linux, build it: `clang -fsanitize=fuzzer libfuzzer-dotnet.cc -o libfuzzer-dotnet`. + +Publish, then instrument **only `LibRed.Core.dll`** — coverage from anything else is noise, and the harness +assembly itself must stay uninstrumented: + +```powershell +dotnet publish test\LibRed.Core.Fuzz -c Release -o fuzz-bin +sharpfuzz fuzz-bin\LibRed.Core.dll +``` + +`sharpfuzz` rewrites the dll in place, so publish afresh rather than instrumenting a dll that already has been. + +Then fuzz one target. libfuzzer-dotnet passes the child exactly one argument (the dll), so the target goes in the +environment. The corpus directory may start empty; libFuzzer grows it. + +```powershell +$env:LIBRED_FUZZ_TARGET = "database" +mkdir corpus\database +libfuzzer-dotnet-windows.exe --target_path=dotnet --target_arg=fuzz-bin\LibRed.Core.Fuzz.dll ` + -timeout=10 -rss_limit_mb=4096 -max_len=256 corpus\database +``` + +`-max_len=256` is about 50 patches, plenty for `database`; the blob targets want more (`-max_len=4096`). Every +`database` run copies and writes a seed file, so it is the slow target — `replay` gets through 300 random inputs +in about four seconds, startup and authoring the seeds included, uninstrumented — and the blob targets are far +faster. Add `-jobs=N -workers=N` to use more cores, `-max_total_time=` to stop on a budget. + +## When it finds something + +libFuzzer stops and writes the input as `crash-` (or `timeout-…`, `oom-…`) in the current directory. +Replay it uninstrumented for the full stack: + +```powershell +dotnet fuzz-bin\LibRed.Core.Fuzz.dll replay database crash- +``` + +`replay` also takes a directory, running every input in it and exiting non-zero if any leaks — useful to check a +corpus against a fix. A leak is fixed in the reader, where the bad value is first read, as the throw site of an +`InvalidDataException` that says what was wrong; never by widening the contract. diff --git a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs index 86ff7edc..761d46bf 100644 --- a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs +++ b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs @@ -29,7 +29,9 @@ public void BuildColumnDescriptor_composes_the_documented_flags_from_the_model() } // ACE writes 0xC0 on a calculated column but reads only 0x40: with 0x80 alone a column is an ordinary one, its - // value read as stored, and with 0x40 alone it is calculated (measured by patching the bit into a text column). + // value read as stored, and with 0x40 alone it is calculated (measured by patching the bit into a text column) — + // here one with no Expression property, so ACE will not load the table: SELECT, COUNT(*) and the column schema + // all fail "Property not found." (measured on this very file). [Theory] [InlineData(0x80, false)] [InlineData(0x40, true)] @@ -58,10 +60,15 @@ public void Only_bit_0x40_makes_a_column_calculated(byte bit, bool calculated) File.WriteAllBytes(path, file); using var read = JetDatabase.Open(path); + if (calculated) + { + Assert.Throws(() => read.OpenTable("T")); + return; + } Table table = read.OpenTable("T"); ColumnDef column = table.Definition.FindColumn("A")!; - Assert.Equal(calculated, column.IsCalculated); - if (!calculated) Assert.Equal("plain", table.Rows().Single()[column.Index]); + Assert.False(column.IsCalculated); + Assert.Equal("plain", table.Rows().Single()[column.Index]); } finally { TemporaryDatabase.Delete(path); } } @@ -198,6 +205,51 @@ public void A_write_once_column_takes_a_value_on_insert_and_refuses_one_on_updat finally { TemporaryDatabase.Delete(path); } } + // The AutoNumber bit 0x04 on a Text column (a damaged descriptor): ACE still takes an explicit value, and sets the + // counter at 0x14 to the value's first four bytes as UTF-16LE, zero-padded (measured: Customers.Address flagged, + // "Street", "500" and "A" inserted). + [Theory] + [InlineData("Street", 0x00740053)] + [InlineData("500", 0x00300035)] + [InlineData("A", 65)] + public void An_explicit_value_in_a_text_column_flagged_AutoNumber_sets_the_counter_to_its_first_four_bytes( + string value, int counter) + { + string path = TemporaryDatabase.CreatePath("autonumber-text-"); + try + { + JetDatabase.Create(path); + int page; + byte[] raw; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("A", JetDataType.Text, 40, IsFixedLength: false)]); + var t = db.Catalog.FindTable("T")!; + page = t.DefinitionPage; + raw = t.FindColumn("A")!.RawDescriptor!; + } + + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + file[page * format.PageSize + at + format.ColumnFlagsOffset] |= (byte)ColumnFlags.AutoNumber; + File.WriteAllBytes(path, file); + int Counter() => TableDefinition.ReadLastAutoNumber(TestDatabases.ReadPage(path, page), format); + Assert.Equal(0, Counter()); + + using (var db = JetDatabase.Open(path, readOnly: false)) + { + Table table = db.OpenTable("T"); + Assert.True(table.Definition.FindColumn("A")!.IsAutoNumber); + table.Insert([1, value]); + Assert.Equal([1, value], table.Rows().Single()); + } + Assert.Equal(counter, Counter()); + } + finally { TemporaryDatabase.Delete(path); } + } + // Without 0x80 ACE will not evaluate a calculated column, whatever its expression: every read of it fails "This // calculated column contains an invalid expression" (measured by clearing the bit on a DAO-created [Qty]*2). [Fact] diff --git a/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs b/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs index 6fe3b6eb..5335b45e 100644 --- a/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs +++ b/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs @@ -1,46 +1,20 @@ -using LibRed; -using LibRed.Catalog; -using LibRed.Storage; using Xunit; namespace LibRed.Core.Tests; // Structural mutation sweep: take a good database, corrupt one field of one page header, and drive every -// read path over the result. -// -// The contract is not "must not throw" — a damaged file SHOULD throw. It is that a damaged file must throw -// InvalidDataException, LibRed's one signal for "these bytes are not a valid database". A caller that wants -// to tell a corrupt file from a bug in the reader has nothing else to catch, and .NET gives it no help: the -// exceptions a parser leaks by accident (ArgumentOutOfRangeException, IndexOutOfRangeException, -// EndOfStreamException) share no base class with InvalidDataException, which derives from SystemException -// rather than IOException. An unhandled one does not degrade, it crashes the caller. -// -// The source databases are AUTHORED HERE, not read from a corpus. Two reasons that matters: -// -// * Coverage is otherwise bounded by whatever one fixture happens to contain. Northwind has no multi-page -// TDEF, no chained long value, no dropped-then-added column and no deep index, so those decode paths -// would never see a corrupt byte at all. LibRed can synthesise a file page-by-page, so the awkward -// shapes are ours to make. -// * A file LibRed wrote tests our reader against our own writer. A leak then points at one of the two, -// rather than at "ACE wrote something we mishandle". -// -// Northwind stays in the set as the one ACE-authored shape, since agreeing with a real Access file is the -// whole point of the format work. +// read path over the result. What counts as a leak, the databases corrupted and the walk over them live in +// MalformedFile (test/LibRed.Shared), shared with the coverage-guided harness in LibRed.Core.Fuzz. public class CorruptFileSweepProbeTests(ITestOutputHelper output) { - /// The exception types a malformed file is allowed to produce. - private static bool IsExpected(Exception e) => - e is InvalidDataException // the contract: these bytes are not a database - or NotSupportedException // a real feature LibRed does not implement yet - or UnauthorizedAccessException; // encrypted, wrong or missing password - [Fact] public void No_structural_mutation_escapes_an_unexpected_exception_type() { // Deliberately small and fixed-seed: this is a REGRESSION guard, not a search. It runs the same 600 // mutations every time, so once green it stays green and finds nothing new. Discovery means raising // this and varying the seed in an offline run — done at 2500 (12,500 mutations, 208k table reads, - // 236k index walks, ~2 min) with no leaks, which is what the committed size is guarding. + // 236k index walks, ~2 min) with no leaks, which is what the committed size is guarding. Open-ended + // search is LibRed.Core.Fuzz's job. const int perSource = 120; var random = new Random(20260907); @@ -52,7 +26,7 @@ public void No_structural_mutation_escapes_an_unexpected_exception_type() int mutations = 0, reachedCatalog = 0, readTables = 0, walkedIndexes = 0; try { - foreach ((string shape, string source) in Sources(directory)) + foreach ((string shape, string source) in MalformedFile.Sources(directory, TestDatabases.NorthwindAccdb)) { byte[] clean = File.ReadAllBytes(source); int pageSize = TestDatabases.FormatOf(source).PageSize; @@ -76,7 +50,7 @@ public void No_structural_mutation_escapes_an_unexpected_exception_type() mutations++; string where = $"{shape} page {page} offset 0x{offset:X2} = 0x{value:X2}"; - foreach ((string stage, Exception? leak) in Exercise(path)) + foreach ((string stage, Exception? leak) in MalformedFile.Exercise(path)) { if (stage.StartsWith("catalog: ok", StringComparison.Ordinal)) reachedCatalog++; if (stage.StartsWith("table '", StringComparison.Ordinal) @@ -114,148 +88,4 @@ public void No_structural_mutation_escapes_an_unexpected_exception_type() Assert.True(walkedIndexes > 0, "no mutation reached an index page — the sweep proved nothing"); Assert.Empty(leaks); } - - /// - /// The good databases to corrupt: one ACE-authored fixture, then shapes LibRed synthesises itself to - /// reach structures the fixture does not contain. - /// - private static IEnumerable<(string Shape, string Path)> Sources(string directory) - { - yield return ("northwind", TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "fuzz-nw-")); - - yield return ("wide-tdef", Author(directory, "wide-tdef", database => - { - // 200 columns spills the definition onto continuation pages, so the TDEF chain gets fuzzed. - database.CreateTable("Wide", - [.. Enumerable.Range(0, 200).Select(i => new ColumnSpec($"c{i}", JetDataType.Int32, 4, IsFixedLength: true))]); - var table = database.OpenTable("Wide"); - var row = new object?[200]; - for (int i = 0; i < 200; i++) row[i] = i; - table.Insert(row); - })); - - yield return ("long-values", Author(directory, "long-values", database => - { - database.CreateTable("Docs", - [new ColumnSpec("Id", JetDataType.Int32, 4, IsFixedLength: true), - new ColumnSpec("Body", JetDataType.Memo, 0, IsFixedLength: false)]); - var table = database.OpenTable("Docs"); - // Inline, single-page and chained, so all three long-value storage forms are present. - foreach ((int id, int length) in new[] { (1, 20), (2, 2000), (3, 40_000) }) - table.Insert([id, new string((char)('a' + id), length)]); - })); - - yield return ("split-index", Author(directory, "split-index", database => - { - database.CreateTable("Keyed", - [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), - new ColumnSpec("V", JetDataType.Text, 60, IsFixedLength: false)], - primaryKey: ["K"]); - var table = database.OpenTable("Keyed"); - // Enough rows to drive the B-tree past a single leaf, so node pages exist to corrupt. - for (int i = 0; i < 1500; i++) table.Insert([i, $"value {i}"]); - })); - - yield return ("altered-columns", Author(directory, "altered-columns", database => - { - database.CreateTable("Churn", - [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), - new ColumnSpec("A", JetDataType.Text, 30, IsFixedLength: false), - new ColumnSpec("B", JetDataType.Text, 30, IsFixedLength: false), - new ColumnSpec("N", JetDataType.Int32, 4, IsFixedLength: true)]); - var table = database.OpenTable("Churn"); - table.Insert([1, "a1", "b1", 11]); - - // The gapped index space and burned ids of a table that has been edited — the shapes that - // produced the row-layout bugs, which a freshly created table cannot reach. - database.DropColumn("Churn", "B"); - database.AddColumn("Churn", new ColumnSpec("D", JetDataType.Text, 30, IsFixedLength: false)); - database.OpenTable("Churn").Insert([2, "a2", 22, "d2"]); - database.AlterColumnTypeInPlace("Churn", "N", - new ColumnSpec("N", JetDataType.Text, 20, IsFixedLength: false)); - })); - } - - /// Synthesises a database from scratch and applies to it. - private static string Author(string directory, string name, Action build) - { - string path = Path.Combine(directory, $"source-{name}.accdb"); - JetDatabase.Create(path); - using (var database = JetDatabase.Open(path, readOnly: false)) - build(database); - return path; - } - - /// - /// Walks everything a caller would, one stage at a time and continuing past failures: open, list - /// the catalog, then each table's rows separately. - /// - /// - /// Per-stage on purpose. Stopping at the first exception means one damaged TDEF hides every path behind - /// it, and the interesting leak is rarely the first thing that breaks. - /// - private static IEnumerable<(string Stage, Exception? Leak)> Exercise(string path) - { - JetDatabase? database = null; - try - { - (string open, Exception? leak) = Try("open", () => database = JetDatabase.Open(path)); - yield return (open, leak); - if (database is null) yield break; - - List tables = []; - yield return Try("catalog", () => tables = [.. database.Catalog.Tables]); - - foreach (TableDefinition table in tables) - { - int rows = 0; - (string read, Exception? rowLeak) = Try($"table '{table.Name}'", () => - { - foreach (object?[] _ in database.OpenTable(table.Name).Rows()) rows++; - }); - yield return ($"{read} ({rows} rows)", rowLeak); - - // A table SCAN reads the usage map and the data pages and never descends a B-tree, so - // without this every index page the sweep corrupts goes unread — the split-index shape was - // building node pages that nothing then looked at. Walking the entries decodes every page - // of the index, which is more of it than a handful of seeks would touch. - foreach (IndexDef index in table.Indexes) - { - int entries = 0; - (string walked, Exception? indexLeak) = - Try($"index '{table.Name}.{index.Name}'", () => - { - Table opened = database.OpenTable(table.Name); - foreach ((byte[] _, RowId _) in - new IndexCursor(opened.Channel, index.RootPage).RawEntries()) entries++; - }); - yield return ($"{walked} ({entries} entries)", indexLeak); - } - } - } - finally { database?.Dispose(); } - } - - private static (string Outcome, Exception? Leak) Try(string stage, Action action) - { - try - { - action(); - return ($"{stage}: ok", null); - } - catch (Exception e) when (IsExpected(e)) - { - return ($"{stage}: rejected — {e.GetType().Name}: {Summarise(e.Message)}", null); - } - catch (Exception e) - { - return ($"{stage}: !! LEAKED {e.GetType().Name}: {Summarise(e.Message)}", e); - } - } - - private static string Summarise(string message) - { - string one = message.ReplaceLineEndings(" ").Trim(); - return one.Length <= 100 ? one : one[..100] + "…"; - } -} \ No newline at end of file +} diff --git a/test/LibRed.Core.Tests/GlobalMapPointerTests.cs b/test/LibRed.Core.Tests/GlobalMapPointerTests.cs index 73ca3d0e..bb4b9f54 100644 --- a/test/LibRed.Core.Tests/GlobalMapPointerTests.cs +++ b/test/LibRed.Core.Tests/GlobalMapPointerTests.cs @@ -126,6 +126,30 @@ public void Released_pages_at_the_end_of_the_file_are_materialized_but_not_alloc finally { TemporaryDatabase.Delete(path); } } + // 0x18 aimed at row 0 of page 94, a long value of 4,076 bytes: read as an inline map it starts at page 352,321,631, + // so its first free page lies past the 2 GiB limit no file can grow beyond. ACE refuses every statement that needs + // a page on this file and adds none (measured), and so does the allocator — at once, without growing the file + // towards the page first. + [Fact] + public void Allocation_refuses_a_free_page_past_the_largest_file() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "globalptr-past-limit-"); + try + { + byte[] longValue = TestDatabases.ReadPage(path, 94); + Assert.Equal("LVAL", System.Text.Encoding.ASCII.GetString(longValue, Format.DataOwnerOffset, 4)); + TestDatabases.WriteMapPointer(path, Format.FreePagesMapPointerOffset, 0, 94); + + using (var channel = PageChannel.Open(path, readOnly: false)) + { + Assert.Throws(() => channel.Allocator.Allocate()); + Assert.Equal(NorthwindPages, channel.PageCount); + } + Assert.Equal(longValue, TestDatabases.ReadPage(path, 94)); + } + finally { TemporaryDatabase.Delete(path); } + } + /// Each case breaks one pointer and leaves the other as Northwind stores it. public static TheoryData InvalidPointers { diff --git a/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs b/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs index 00437db7..b996c096 100644 --- a/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs +++ b/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs @@ -139,6 +139,56 @@ public void Full_index_cursor_rejects_a_cycle_without_recursive_descent() finally { TemporaryDatabase.Delete(path); } } + // B's variable index patched to A's, so the two columns share one slot: B reads A's value, while B's index still + // holds the row under the value B was written with. A write of that row looks for the entry under the value it + // reads and finds none. ACE refuses the same write on the same damage — Customers.City moved onto CompanyName's + // slot — with "The search key was not found in any record." and leaves the table as it was (measured), so this is + // damage, not a refused value, and the statement rolls back. + [Theory] + [InlineData("update")] + [InlineData("delete")] + public void A_write_whose_index_entry_the_row_no_longer_matches_is_rejected_as_corruption(string statement) + { + string path = TemporaryDatabase.CreatePath("index-orphaned-"); + try + { + JetDatabase.Create(path); + int page; + byte[] a, b; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("A", JetDataType.Text, 40, IsFixedLength: false), + new ColumnSpec("B", JetDataType.Text, 40, IsFixedLength: false)]); + db.CreateIndex("T", "ix", [("B", false)]); + db.OpenTable("T").Insert([1, "aa", "bb"]); + TableDefinition t = db.Catalog.FindTable("T")!; + (page, a, b) = (t.DefinitionPage, t.FindColumn("A")!.RawDescriptor!, t.FindColumn("B")!.RawDescriptor!); + } + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(b); + Assert.True(at >= 0); + a.AsSpan(format.ColumnVariableIndexOffset, 2).CopyTo(file.AsSpan(page * format.PageSize + at + format.ColumnVariableIndexOffset)); + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path, readOnly: false); + Table table = damaged.OpenTable("T"); + (RowId id, object?[] row) = table.Rows().WithIds().Single(); + Assert.Equal([1, "aa", "aa"], row); + if (statement == "delete") + Assert.Throws(() => table.Delete(id)); + else + { + var changed = (object?[])row.Clone(); + changed[2] = "cc"; + Assert.Throws(() => table.Update(id, changed)); + } + Assert.Equal([1, "aa", "aa"], table.Rows().Single()); + } + finally { TemporaryDatabase.Delete(path); } + } + private static (int Root, int Owner) IndexIdentity(string path) { using var db = JetDatabase.Open(path); diff --git a/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj b/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj index 114954d7..d00c4c18 100644 --- a/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj +++ b/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj @@ -35,7 +35,8 @@ wholesale (..\Shared\**\*.cs) and do not all reference LibRed.Core. --> - + + diff --git a/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs b/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs index cb704d21..474b6583 100644 --- a/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs +++ b/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs @@ -120,6 +120,45 @@ public void The_close_lengthens_the_released_map_to_cover_the_highest_page_relea finally { TemporaryDatabase.Delete(path); } } + // A released map whose start page is -2,147,483,648 (its high byte damaged), every bit clear: ACE's close leaves + // it as it was and merges the pages a session released into the free map exactly as on the undamaged file + // (measured, releasing a picture's three long-value pages). + [Fact] + public void The_close_leaves_a_released_map_starting_below_page_zero_as_it_is_and_frees_the_pages() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "release-negative-"); + try + { + int holderPage; + byte[] holder, record; + using (var channel = PageChannel.Open(path, readOnly: true)) + { + DataPage.RowSlot slot; + (_, holderPage, holder, slot) = TestDatabases.GlobalMap(channel, Format.ReleasedPagesMapPointerOffset); + System.Buffers.Binary.BinaryPrimitives.WriteInt32LittleEndian( + InlineMap(holder, slot)[Format.UsageMapStartPageOffset..], int.MinValue); + record = InlineMap(holder, slot).ToArray(); + } + TestDatabases.WritePage(path, holderPage, holder); + + using (var db = JetDatabase.Open(path, readOnly: false)) + { + var allocator = db.OpenTable("MSysObjects").Channel.Allocator; + allocator.Release(300); + allocator.Release(301); + } + + using (var channel = PageChannel.Open(path, readOnly: true)) + { + Assert.True(FreeMapBit(channel, 300)); + Assert.True(FreeMapBit(channel, 301)); + (_, _, byte[] after, DataPage.RowSlot slot) = TestDatabases.GlobalMap(channel, Format.ReleasedPagesMapPointerOffset); + Assert.Equal(record, InlineMap(after, slot).ToArray()); + } + } + finally { TemporaryDatabase.Delete(path); } + } + [Fact] public void Pages_already_in_the_released_map_are_merged_by_a_close_that_wrote_but_not_by_an_idle_one() { diff --git a/test/LibRed.Shared/MalformedFile.cs b/test/LibRed.Shared/MalformedFile.cs new file mode 100644 index 00000000..7b97084e --- /dev/null +++ b/test/LibRed.Shared/MalformedFile.cs @@ -0,0 +1,233 @@ +using LibRed.Catalog; +using LibRed.Storage; + +namespace LibRed.Tests.Shared; + +/// +/// What a damaged database file is allowed to do to a reader, the good databases to damage, and the walk that +/// drives every read path over the result. Shared by the fixed-seed sweep in LibRed.Core.Tests and the +/// coverage-guided harness in LibRed.Core.Fuzz, so the two cannot disagree about what counts as a leak. +/// +/// +/// The contract is not "must not throw" — a damaged file SHOULD throw. It is that a damaged file must throw +/// InvalidDataException, LibRed's one signal for "these bytes are not a valid database". A caller that wants +/// to tell a corrupt file from a bug in the reader has nothing else to catch, and .NET gives it no help: the +/// exceptions a parser leaks by accident (ArgumentOutOfRangeException, IndexOutOfRangeException, +/// EndOfStreamException) share no base class with InvalidDataException, which derives from SystemException +/// rather than IOException. An unhandled one does not degrade, it crashes the caller. +/// +internal static class MalformedFile +{ + /// The exception types a malformed file is allowed to produce. + public static bool IsExpected(Exception e) => + e is InvalidDataException // the contract: these bytes are not a database + or NotSupportedException // a real feature LibRed does not implement yet + or UnauthorizedAccessException; // encrypted, wrong or missing password + + /// + /// The good databases to corrupt: one ACE-authored fixture, then shapes LibRed synthesises itself to + /// reach structures the fixture does not contain. Each is written into . + /// + /// + /// The source databases are AUTHORED HERE, not read from a corpus. Two reasons that matters: + /// + /// Coverage is otherwise bounded by whatever one fixture happens to contain. Northwind has no multi-page + /// TDEF, no chained long value, no dropped-then-added column and no deep index, so those decode paths + /// would never see a corrupt byte at all. LibRed can synthesise a file page-by-page, so the awkward + /// shapes are ours to make. + /// A file LibRed wrote tests our reader against our own writer. A leak then points at one of the two, + /// rather than at "ACE wrote something we mishandle". + /// + /// Northwind stays in the set as the one ACE-authored shape, since agreeing with a real Access file is the + /// whole point of the format work. + /// + public static IEnumerable<(string Shape, string Path)> Sources(string directory, string northwind) + { + string copy = Path.Combine(directory, "source-northwind.accdb"); + File.Copy(northwind, copy); + yield return ("northwind", copy); + + yield return ("wide-tdef", Author(directory, "wide-tdef", database => + { + // 200 columns spills the definition onto continuation pages, so the TDEF chain gets fuzzed. + database.CreateTable("Wide", + [.. Enumerable.Range(0, 200).Select(i => new ColumnSpec($"c{i}", JetDataType.Int32, 4, IsFixedLength: true))]); + var table = database.OpenTable("Wide"); + var row = new object?[200]; + for (int i = 0; i < 200; i++) row[i] = i; + table.Insert(row); + })); + + yield return ("long-values", Author(directory, "long-values", database => + { + database.CreateTable("Docs", + [new ColumnSpec("Id", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("Body", JetDataType.Memo, 0, IsFixedLength: false)]); + var table = database.OpenTable("Docs"); + // Inline, single-page and chained, so all three long-value storage forms are present. + foreach ((int id, int length) in new[] { (1, 20), (2, 2000), (3, 40_000) }) + table.Insert([id, new string((char)('a' + id), length)]); + })); + + yield return ("split-index", Author(directory, "split-index", database => + { + database.CreateTable("Keyed", + [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("V", JetDataType.Text, 60, IsFixedLength: false)], + primaryKey: ["K"]); + var table = database.OpenTable("Keyed"); + // Enough rows to drive the B-tree past a single leaf, so node pages exist to corrupt. + for (int i = 0; i < 1500; i++) table.Insert([i, $"value {i}"]); + })); + + yield return ("altered-columns", Author(directory, "altered-columns", database => + { + database.CreateTable("Churn", + [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("A", JetDataType.Text, 30, IsFixedLength: false), + new ColumnSpec("B", JetDataType.Text, 30, IsFixedLength: false), + new ColumnSpec("N", JetDataType.Int32, 4, IsFixedLength: true)]); + var table = database.OpenTable("Churn"); + table.Insert([1, "a1", "b1", 11]); + + // The gapped index space and burned ids of a table that has been edited — the shapes that + // produced the row-layout bugs, which a freshly created table cannot reach. + database.DropColumn("Churn", "B"); + database.AddColumn("Churn", new ColumnSpec("D", JetDataType.Text, 30, IsFixedLength: false)); + database.OpenTable("Churn").Insert([2, "a2", 22, "d2"]); + database.AlterColumnTypeInPlace("Churn", "N", + new ColumnSpec("N", JetDataType.Text, 20, IsFixedLength: false)); + })); + } + + /// Synthesises a database from scratch and applies to it. + private static string Author(string directory, string name, Action build) + { + string path = Path.Combine(directory, $"source-{name}.accdb"); + JetDatabase.Create(path); + using (var database = JetDatabase.Open(path, readOnly: false)) + build(database); + return path; + } + + /// + /// Walks everything a caller would, one stage at a time and continuing past failures: open, list + /// the catalog, then each table's rows separately. With , in each user table still + /// listed, the first of its first 32 rows the write accepts is also rewritten in place, deleted and inserted + /// again before its indexes are walked. + /// + /// + /// Per-stage on purpose. Stopping at the first exception means one damaged TDEF hides every path behind + /// it, and the interesting leak is rarely the first thing that breaks. + /// + public static IEnumerable<(string Stage, Exception? Leak)> Exercise(string path, string? password = null, bool write = false) + { + JetDatabase? database = null; + try + { + (string open, Exception? leak) = Try("open", () => database = JetDatabase.Open(path, readOnly: !write, password: password)); + yield return (open, leak); + if (database is null) yield break; + + List tables = []; + yield return Try("catalog", () => tables = [.. database.Catalog.Tables]); + + foreach (TableDefinition table in tables) + { + // A write allocates through page 0's free-pages map wherever it points, and so does ACE: aimed at a + // table's own map, ACE takes that table's live pages without looking at them (measured, + // docs/format/page-05-usage-maps.md §9.1). So on a damaged file a write can overwrite the catalog's + // pages, and a table listed above is gone when the walk reaches it — or reaches its indexes, after + // its own write. Asking for it by name then gets the answer for a table that is not there; that is + // a refusal of the name, not a leak, so the walk only follows what is still listed. + bool listed = true; + if (write) + { + yield return Try($"find '{table.Name}'", () => listed = database.Catalog.FindTable(table.Name) is not null); + if (!listed) continue; + } + + int rows = 0; + (string read, Exception? rowLeak) = Try($"table '{table.Name}'", () => + { + foreach (object?[] _ in database.OpenTable(table.Name).Rows()) rows++; + }); + yield return ($"{read} ({rows} rows)", rowLeak); + + // A write reads what it changes — the slot it rewrites, the free-space map it allocates from, + // the index entry it removes — and takes every value it finds there as its next offset. Writing + // the row back with its own values keeps the workload valid on an undamaged file. On a damaged one + // the row's values can break its own damaged schema — a Null key, a value past its column, a record + // past the page — and a write refuses them with InvalidOperationException, as ACE refuses them too. + // So here that is a refusal, not a leak, and the next row is tried; what a write may not do is leak + // anything else. The rewrite declares no column changed and leaves Table.Update to find that none + // did: declaring them all would also "update" a write-once column, which ACE refuses whatever the + // value, and so refuse every row. Only the first rows are tried: when they are all refused, the damage + // is the table's — a schema whose every record is too large — and trying each of thousands of rows + // spends the fuzzer's time limit on the same refusal. + if (write && !table.IsSystem) + yield return Try($"write '{table.Name}'", () => + { + Table opened = database.OpenTable(table.Name); + foreach ((RowId id, object?[] values) in opened.Rows().WithIds().Take(32).ToList()) + { + try + { + opened.Update(id, values, new HashSet()); + opened.Delete(id); + opened.Insert(values); + break; + } + catch (InvalidOperationException) { } + } + }); + if (write) + { + yield return Try($"find '{table.Name}' again", () => listed = database.Catalog.FindTable(table.Name) is not null); + if (!listed) continue; + } + + // A table SCAN reads the usage map and the data pages and never descends a B-tree, so + // without this every index page the sweep corrupts goes unread — the split-index shape was + // building node pages that nothing then looked at. Walking the entries decodes every page + // of the index, which is more of it than a handful of seeks would touch. + foreach (IndexDef index in table.Indexes) + { + int entries = 0; + (string walked, Exception? indexLeak) = + Try($"index '{table.Name}.{index.Name}'", () => + { + Table opened = database.OpenTable(table.Name); + foreach ((byte[] _, RowId _) in + new IndexCursor(opened.Channel, index.RootPage).RawEntries()) entries++; + }); + yield return ($"{walked} ({entries} entries)", indexLeak); + } + } + } + finally { database?.Dispose(); } + } + + private static (string Outcome, Exception? Leak) Try(string stage, Action action) + { + try + { + action(); + return ($"{stage}: ok", null); + } + catch (Exception e) when (IsExpected(e)) + { + return ($"{stage}: rejected — {e.GetType().Name}: {Summarise(e.Message)}", null); + } + catch (Exception e) + { + return ($"{stage}: !! LEAKED {e.GetType().Name}: {Summarise(e.Message)}", e); + } + } + + private static string Summarise(string message) + { + string one = message.ReplaceLineEndings(" ").Trim(); + return one.Length <= 100 ? one : one[..100] + "…"; + } +} From fcae78af81de854f166922e9c419c0157bc5f8ae Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 2 Nov 2026 23:40:37 +0800 Subject: [PATCH 12/27] Look up complex columns on delete only for a table that has one Table.Delete asked MSysComplexColumns for every table's complex columns, seeking its ConceptualTableID index with the table's definition page. With that column's type byte damaged from Long to Byte, the seek key of a table past page 255 overflowed the Byte, and every delete from such a table threw an OverflowException. Only a table with a Complex column has values elsewhere to remove, so only it asks the registry now; ACE inserts, updates and deletes rows of other tables on this damage as usual (measured). Co-Authored-By: Claude Opus 5.5 --- src/LibRed/LibRed.Core/Storage/Table.cs | 6 +++- src/LibRed/docs/format/system-catalog.md | 4 ++- test/LibRed.Core.Tests/ComplexColumnTests.cs | 36 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/LibRed/LibRed.Core/Storage/Table.cs b/src/LibRed/LibRed.Core/Storage/Table.cs index 4b6420d4..dc63680d 100644 --- a/src/LibRed/LibRed.Core/Storage/Table.cs +++ b/src/LibRed/LibRed.Core/Storage/Table.cs @@ -258,7 +258,11 @@ public void Delete(RowId id) Write(() => { object?[] values = GetRow(id, StoredColumns) ?? throw new InvalidOperationException($"Row '{id}' does not exist."); - foreach (ComplexColumn complex in _catalog.LoadComplexColumns(Definition.DefinitionPage)) + // Only a table with a complex column has values elsewhere to remove, so only it asks MSysComplexColumns: + // on a file whose registry is damaged, ACE deletes from any other table as usual (measured). + IEnumerable complexColumns = Definition.Columns.Any(c => c.Type == JetDataType.Complex) + ? _catalog.LoadComplexColumns(Definition.DefinitionPage) : []; + foreach (ComplexColumn complex in complexColumns) { if (values[complex.OwnerTable.RequireColumn(complex.ColumnName).Index] is not { } raw) continue; int recordId = Convert.ToInt32(raw, System.Globalization.CultureInfo.InvariantCulture); diff --git a/src/LibRed/docs/format/system-catalog.md b/src/LibRed/docs/format/system-catalog.md index 2f0215db..72c90318 100644 --- a/src/LibRed/docs/format/system-catalog.md +++ b/src/LibRed/docs/format/system-catalog.md @@ -998,7 +998,9 @@ Four layers — the user table, then three kinds of ordinary hidden/system table 2. **`MSysComplexColumns`** maps each complex column to its backing table: `(ColumnName, ComplexID, ComplexTypeObjectID, ConceptualTableID, FlatTableID)`. E.g. `Attachments | 3 | 39 | 79 | 150` = the `Attachments` column of table `79`, element type **39** - (`MSysComplexType_Attachment`), backed by flat table **150** = `f__Attachments`. + (`MSysComplexType_Attachment`), backed by flat table **150** = `f__Attachments`. A write to a table + with no `Complex` column does not depend on it: with `ConceptualTableID`'s type byte damaged from Long to + Byte, ACE inserts, updates and deletes rows of such a table as usual (verified). 3. **`MSysComplexType_*`** — nine schema templates, one per element subtype, matching the DAO `dbComplex*` codes: `UnsignedByte, Short, Long, IEEESingle, IEEEDouble, GUID, Decimal, Text, Attachment`. `MSysComplexType_Attachment` = `FileData:Ole, FileFlags:Int32, FileName:Text, FileTimeStamp:DateTime, diff --git a/test/LibRed.Core.Tests/ComplexColumnTests.cs b/test/LibRed.Core.Tests/ComplexColumnTests.cs index 3dd3665f..045474a9 100644 --- a/test/LibRed.Core.Tests/ComplexColumnTests.cs +++ b/test/LibRed.Core.Tests/ComplexColumnTests.cs @@ -379,6 +379,42 @@ public void A_column_that_is_not_complex_is_rejected() Assert.Throws(() => db.ReadComplexValues("Customers", "CustomerID", 1)); } + // MSysComplexColumns.ConceptualTableID's type byte damaged from Long (0x04) to Byte (0x02): a write still looks up + // its table's complex columns there, by the table's definition page — 283 for Shippers, which no Byte holds. ACE + // inserts and deletes a Shippers row on this file as usual (measured), and so does LibRed. + [Fact] + public void A_write_goes_ahead_when_the_registry_types_its_owner_column_as_another_kind() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "complex-owner-type-"); + try + { + int page; + byte[] raw; + using (var db = JetDatabase.Open(path)) + { + TableDefinition registry = db.Catalog.FindTable("MSysComplexColumns")!; + page = registry.DefinitionPage; + raw = registry.FindColumn("ConceptualTableID")!.RawDescriptor!; + Assert.True(db.Catalog.FindTable("Shippers")!.DefinitionPage > byte.MaxValue); + } + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + Assert.Equal((byte)JetDataType.Int32, file[page * format.PageSize + at + format.ColumnTypeOffset]); + file[page * format.PageSize + at + format.ColumnTypeOffset] = (byte)JetDataType.Byte; + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path, readOnly: false); + var shippers = damaged.OpenTable("Shippers"); + shippers.Insert([null, "Fuzz", null]); + var (id, _) = shippers.Rows().WithIds().Single(r => (string?)r.Values[1] == "Fuzz"); + shippers.Delete(id); + Assert.Equal(3, shippers.Rows().Count()); + } + finally { TemporaryDatabase.Delete(path); } + } + [Theory] [InlineData(new byte[] { 1, 2, 3 })] // shorter than the outer header [InlineData(new byte[] { 9, 0, 0, 0, 4, 0, 0, 0, 1, 2, 3, 4 })] // unknown compression flag From 2761628f59d1589b1a39c2d9cbb8c5416c99178f Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Tue, 3 Nov 2026 18:04:59 +0800 Subject: [PATCH 13/27] Take an OLE value's first four bytes as the AutoNumber counter, as ACE does On an OLE column whose descriptor carries the AutoNumber flag (a damaged file), an explicit insert passed the binary value to Convert.ToInt32 to update the counter at 0x14, which threw InvalidCastException. ACE sets the counter to the value's first four bytes, as it does a text value's first four UTF-16 bytes (measured: bytes 01 02 03 04 05 06 give 0x04030201), so the binary value now takes the same path. Co-Authored-By: Claude Opus 5.5 --- src/LibRed/LibRed.Core/Storage/RowInserter.cs | 15 ++++--- src/LibRed/docs/format/page-02a-tdef.md | 4 ++ .../ColumnDescriptorFlagTests.cs | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/LibRed/LibRed.Core/Storage/RowInserter.cs b/src/LibRed/LibRed.Core/Storage/RowInserter.cs index a9b9429e..066b5683 100644 --- a/src/LibRed/LibRed.Core/Storage/RowInserter.cs +++ b/src/LibRed/LibRed.Core/Storage/RowInserter.cs @@ -1335,12 +1335,15 @@ private void UpdateTdefCounters(JetFormatBase format, byte[] tdef, object?[] val // a UI-authored Random AutoNumber reads last-value 0). Advancing it would be meaningless (random ids // don't form a monotone sequence) and diverge from Access's on-disk state. if (column.IsRandomAutoNumber) continue; - // The counter is a value's first four bytes. On a Text column that carries the AutoNumber flag — a - // damaged descriptor — ACE takes them from the UTF-16 text, zero-padded (measured: "Street" sets 0x14 to - // 0x00740053, "A" to 65). - int assigned = value is string text - ? (text.Length > 0 ? text[0] : 0) | (text.Length > 1 ? text[1] << 16 : 0) - : Convert.ToInt32(value, CultureInfo.InvariantCulture); + // The counter is a value's first four bytes. On a Text or OLE column that carries the AutoNumber flag — a + // damaged descriptor — ACE takes them from the UTF-16 text, zero-padded, or from the binary value + // (measured: "Street" sets 0x14 to 0x00740053, "A" to 65, bytes 01 02 03 04 05 06 to 0x04030201). + int assigned = value switch + { + string text => (text.Length > 0 ? text[0] : 0) | (text.Length > 1 ? text[1] << 16 : 0), + byte[] bytes => bytes.Take(4).Select((b, i) => b << (8 * i)).Aggregate(0, (counter, b) => counter | b), + _ => Convert.ToInt32(value, CultureInfo.InvariantCulture), + }; int highWater = TableDefinition.ReadLastAutoNumber(tdef, format); // An id this insert *generated* always becomes the new high-water: it came from 0x14 + increment, // so it is by construction the next value in the sequence. That includes the wrap past diff --git a/src/LibRed/docs/format/page-02a-tdef.md b/src/LibRed/docs/format/page-02a-tdef.md index 006ad28e..7a448078 100644 --- a/src/LibRed/docs/format/page-02a-tdef.md +++ b/src/LibRed/docs/format/page-02a-tdef.md @@ -101,6 +101,10 @@ > zero-padded: `'Street'` → `0x00740053`, `'500'` → `0x00300035`, `'A'` → `65`. A generated id goes the other way — > with the flag byte `0x06` the id's four bytes are stored as two characters (`0x00740054` → `'Tt'`); with `0xEE` > (`0x40` set as well) ACE stores `'\x01\0'` and resets `0x14` to `1`. LibRed matches the explicit case only. +> On an OLE column flagged the same way the counter likewise takes a binary value's first four bytes: `01 02 03 04 +> 05 06` → `0x04030201`. With the table's own AutoNumber (`Categories.CategoryID`) beside it, an `INSERT` that +> leaves that column out is refused *"You must enter a value in the 'Categories.CategoryID' field"*, its id +> burned, and a one-byte binary value left `0x14` at the explicit `CategoryID` rather than taking the byte. > **Reader/writer count guardrails.** LibRed validates the documented 255-column and 32-real-index > limits before allocating count-sized structures, rejects negative logical/real index counts, and checks diff --git a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs index 761d46bf..4ee9f410 100644 --- a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs +++ b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs @@ -250,6 +250,45 @@ public void An_explicit_value_in_a_text_column_flagged_AutoNumber_sets_the_count finally { TemporaryDatabase.Delete(path); } } + // The same bit on an OLE column: an explicit binary value sets the counter to its first four bytes (measured: + // Categories.Picture flagged, bytes 01 02 03 04 05 06 set 0x14 to 0x04030201). + [Fact] + public void An_explicit_value_in_an_ole_column_flagged_AutoNumber_sets_the_counter_to_its_first_four_bytes() + { + string path = TemporaryDatabase.CreatePath("autonumber-ole-"); + try + { + JetDatabase.Create(path); + int page; + byte[] raw; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("P", JetDataType.Ole, 0, IsFixedLength: false)]); + var t = db.Catalog.FindTable("T")!; + page = t.DefinitionPage; + raw = t.FindColumn("P")!.RawDescriptor!; + } + + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + file[page * format.PageSize + at + format.ColumnFlagsOffset] |= (byte)ColumnFlags.AutoNumber; + File.WriteAllBytes(path, file); + + byte[] value = [1, 2, 3, 4, 5, 6]; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + Table table = db.OpenTable("T"); + Assert.True(table.Definition.FindColumn("P")!.IsAutoNumber); + table.Insert([1, value]); + Assert.Equal(value, table.Rows().Single()[1]); + } + Assert.Equal(0x04030201, TableDefinition.ReadLastAutoNumber(TestDatabases.ReadPage(path, page), format)); + } + finally { TemporaryDatabase.Delete(path); } + } + // Without 0x80 ACE will not evaluate a calculated column, whatever its expression: every read of it fails "This // calculated column contains an invalid expression" (measured by clearing the bit on a DAO-created [Qty]*2). [Fact] From 6f378097e08691db8513c42aa82072bf5b072110 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 4 Nov 2026 20:30:09 +0800 Subject: [PATCH 14/27] Close without throwing when the release is a map LibRed cannot grow Closing a writable JetDatabase returns the pages its session released, and a release that cannot run on a damaged file was already absorbed: it runs in its own transaction, so it writes nothing and the pages stay released. Only InvalidDataException was caught, though. A released map turned reference form needs a bitmap page, and a free map with a nonzero start page and no free page refuses that allocation with NotSupportedException, which then escaped from Dispose. The close now absorbs that refusal the same way. Co-Authored-By: Claude Opus 5.5 --- src/LibRed/LibRed.Core/JetDatabase.cs | 9 ++--- test/LibRed.Core.Tests/ReleaseAtCloseTests.cs | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/LibRed/LibRed.Core/JetDatabase.cs b/src/LibRed/LibRed.Core/JetDatabase.cs index 6d658a73..d2916de8 100644 --- a/src/LibRed/LibRed.Core/JetDatabase.cs +++ b/src/LibRed/LibRed.Core/JetDatabase.cs @@ -788,11 +788,12 @@ public void Dispose() _channel.Allocator.ReturnReleasedPages(); } } - catch (InvalidDataException) + catch (Exception e) when (e is InvalidDataException or NotSupportedException) { - // The global maps were damaged after the open validated them. The release runs in its own transaction, - // so nothing of it was written: the released pages simply stay unreusable, which Compact reclaims — - // better than a close that throws out of a using block and hides whatever was already unwinding. + // The global maps are damaged, or in a shape LibRed cannot grow, past what the open validated. The + // release runs in its own transaction, so nothing of it was written: the released pages simply stay + // unreusable, which Compact reclaims — better than a close that throws out of a using block and hides + // whatever was already unwinding. } finally { diff --git a/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs b/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs index 474b6583..88218b9f 100644 --- a/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs +++ b/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs @@ -159,6 +159,42 @@ record = InlineMap(holder, slot).ToArray(); finally { TemporaryDatabase.Delete(path); } } + // A close whose release cannot run — here a released map turned reference form, which needs a bitmap page, and + // a free map with no free page and a nonzero start page, which LibRed does not grow — does not throw out of + // Dispose. The release runs in its own transaction, so it writes nothing, and the released page stays released. + [Fact] + public void A_close_whose_release_cannot_run_writes_nothing_and_does_not_throw() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "release-cannot-"); + try + { + int holderPage; + byte[] holder; + using (var channel = PageChannel.Open(path, readOnly: true)) + { + DataPage.RowSlot free, released; + (_, holderPage, holder, free) = TestDatabases.GlobalMap(channel, Format.FreePagesMapPointerOffset); + (_, _, _, released) = TestDatabases.GlobalMap(channel, Format.ReleasedPagesMapPointerOffset); + Span freeMap = InlineMap(holder, free); + System.Buffers.Binary.BinaryPrimitives.WriteInt32LittleEndian(freeMap[Format.UsageMapStartPageOffset..], 8); + UsageMap.InlineBits(freeMap, Format).Clear(); + Assert.Equal(Format.UsageMapReferenceRecordSize, released.Length); + Assert.All(UsageMap.InlineBits(InlineMap(holder, released), Format).ToArray(), b => Assert.Equal(0, b)); + holder[released.Offset] = (byte)UsageMapType.Reference; + } + TestDatabases.WritePage(path, holderPage, holder); + + var db = JetDatabase.Open(path, readOnly: false); + PageAllocator allocator = db.OpenTable("MSysObjects").Channel.Allocator; + Assert.Throws(() => allocator.Allocate()); // the free map LibRed cannot grow + allocator.Release(300); + db.Dispose(); + + Assert.Equal(holder, TestDatabases.ReadPage(path, holderPage)); + } + finally { TemporaryDatabase.Delete(path); } + } + [Fact] public void Pages_already_in_the_released_map_are_merged_by_a_close_that_wrote_but_not_by_an_idle_one() { From d372a0c89c818a3a3a720563c3f064c10da3e1be Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Thu, 5 Nov 2026 02:35:28 +0800 Subject: [PATCH 15/27] Refuse a row whose AutoNumber column cannot hold the counter, as ACE does On a fixed column whose descriptor carries the AutoNumber flag (a damaged file), an explicit insert passed the value to Convert.ToInt32 to update the counter at 0x14; a Date/Time value threw InvalidCastException. Measured against ACE, the column's width decides. The counter is four bytes: a Single takes its own bits (0.25 gives 0x3E800000), while an Integer, Currency or Date/Time column refuses the row, explicit value and all, with "The field is too small to accept the amount of data you attempted to add." after drawing an id, which stays burned. Insert now does the same, refusing before the row is written. Co-Authored-By: Claude Opus 5.5 --- src/LibRed/LibRed.Core/Storage/RowInserter.cs | 29 ++++++--- src/LibRed/docs/format/page-02a-tdef.md | 5 ++ .../ColumnDescriptorFlagTests.cs | 60 +++++++++++++++++++ 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/LibRed/LibRed.Core/Storage/RowInserter.cs b/src/LibRed/LibRed.Core/Storage/RowInserter.cs index 066b5683..3963a66d 100644 --- a/src/LibRed/LibRed.Core/Storage/RowInserter.cs +++ b/src/LibRed/LibRed.Core/Storage/RowInserter.cs @@ -1225,9 +1225,17 @@ private TableDefinition ReadDefinition() /// private bool[]? AssignAutoNumbers(JetFormatBase format, object?[] values, ReadOnlySpan tdef) { + // The counter is four bytes. A fixed column of another width carrying the AutoNumber flag — a damaged + // descriptor — cannot hold it: ACE draws the id all the same and then refuses the row, explicit value or not + // (measured on Integer, Currency and Date/Time columns; Single and Long, four bytes, take theirs). A random + // AutoNumber draws no id, so it is left as it was. + static bool CannotHoldTheCounter(ColumnDef column) => + column.IsFixedLength && column.Type != JetDataType.Boolean && column.Length != sizeof(int) + && !column.IsRandomAutoNumber; + bool needed = false; foreach (ColumnDef column in _table.Columns) - if (column.IsAutoNumber && values[column.Index] is null or DBNull) { needed = true; break; } + if (column.IsAutoNumber && (values[column.Index] is null or DBNull || CannotHoldTheCounter(column))) { needed = true; break; } if (!needed) return null; int highWater = TableDefinition.ReadLastAutoNumber(tdef, format); @@ -1241,7 +1249,8 @@ private TableDefinition ReadDefinition() bool[] generated = new bool[values.Length]; foreach (ColumnDef column in _table.Columns) - if (column.IsAutoNumber && column.Type != JetDataType.Complex && values[column.Index] is null or DBNull) + if (column.IsAutoNumber && column.Type != JetDataType.Complex + && (values[column.Index] is null or DBNull || CannotHoldTheCounter(column))) { if (column.IsRandomAutoNumber) // "Random" AutoNumber (DefaultValue = GenUniqueID()): a random Int32, independent of the @@ -1253,9 +1262,13 @@ private TableDefinition ReadDefinition() // Seed-Increment, so the first assigned id is the Seed. The addition is deliberately // unchecked: past int.MaxValue the counter wraps to int.MinValue and keeps going, which // is exactly what ACE does (no overflow error exists — see AceAutoNumberOverflowProbeTest). - values[column.Index] = highWater = unchecked(highWater + column.Increment); - generated[column.Index] = true; + highWater = unchecked(highWater + column.Increment); _channel.KeepThroughRollback(_table.DefinitionPage, format.TdefLastAutoNumberOffset, highWater); + if (CannotHoldTheCounter(column)) + throw new InvalidOperationException( + $"The field '{column.Name}' is too small to accept the amount of data you attempted to add."); + values[column.Index] = highWater; + generated[column.Index] = true; } } return generated; @@ -1335,12 +1348,14 @@ private void UpdateTdefCounters(JetFormatBase format, byte[] tdef, object?[] val // a UI-authored Random AutoNumber reads last-value 0). Advancing it would be meaningless (random ids // don't form a monotone sequence) and diverge from Access's on-disk state. if (column.IsRandomAutoNumber) continue; - // The counter is a value's first four bytes. On a Text or OLE column that carries the AutoNumber flag — a - // damaged descriptor — ACE takes them from the UTF-16 text, zero-padded, or from the binary value - // (measured: "Street" sets 0x14 to 0x00740053, "A" to 65, bytes 01 02 03 04 05 06 to 0x04030201). + // The counter is a value's first four bytes. On a Text, OLE or Single column that carries the AutoNumber + // flag — a damaged descriptor — ACE takes them from the UTF-16 text, zero-padded, from the binary value, + // or from the float (measured: "Street" sets 0x14 to 0x00740053, "A" to 65, bytes 01 02 03 04 05 06 to + // 0x04030201, 0.25 to 0x3E800000). int assigned = value switch { string text => (text.Length > 0 ? text[0] : 0) | (text.Length > 1 ? text[1] << 16 : 0), + float single => BitConverter.SingleToInt32Bits(single), byte[] bytes => bytes.Take(4).Select((b, i) => b << (8 * i)).Aggregate(0, (counter, b) => counter | b), _ => Convert.ToInt32(value, CultureInfo.InvariantCulture), }; diff --git a/src/LibRed/docs/format/page-02a-tdef.md b/src/LibRed/docs/format/page-02a-tdef.md index 7a448078..b9e3b6b6 100644 --- a/src/LibRed/docs/format/page-02a-tdef.md +++ b/src/LibRed/docs/format/page-02a-tdef.md @@ -105,6 +105,11 @@ > 05 06` → `0x04030201`. With the table's own AutoNumber (`Categories.CategoryID`) beside it, an `INSERT` that > leaves that column out is refused *"You must enter a value in the 'Categories.CategoryID' field"*, its id > burned, and a one-byte binary value left `0x14` at the explicit `CategoryID` rather than taking the byte. +> On a fixed column the width decides: a 4-byte `Single` takes its own bits (`0.25` → `0x3E800000`), while an +> `Integer`, `Currency` or `Date/Time` column refuses the row, explicit value and all, with *"The field is too +> small to accept the amount of data you attempted to add."* and `0x14` advanced by one — the id is drawn and +> burned. DAO refuses to create the flag on a GUID column at all (`dbAutoIncrField` on `dbGUID`: *"Invalid +> argument"*). > **Reader/writer count guardrails.** LibRed validates the documented 255-column and 32-real-index > limits before allocating count-sized structures, rejects negative logical/real index counts, and checks diff --git a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs index 4ee9f410..1c2e29e9 100644 --- a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs +++ b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs @@ -289,6 +289,66 @@ public void An_explicit_value_in_an_ole_column_flagged_AutoNumber_sets_the_count finally { TemporaryDatabase.Delete(path); } } + // The same bit on fixed columns. A 4-byte Single takes its own bits as the counter; a column of any other width + // cannot hold the 4-byte counter, and ACE refuses the row — explicit value and all — with the id burned + // (measured: Order Details.Discount 0.25 set 0x14 to 0x3E800000; Quantity, UnitPrice, Orders.Freight and + // OrderDate refused "The field is too small to accept the amount of data you attempted to add.", 0x14 + 1). + [Theory] + [InlineData(JetDataType.Single, 4, 0.25f, 0x3E800000, false)] + [InlineData(JetDataType.Int16, 2, (short)-2, 1, true)] + [InlineData(JetDataType.Currency, 8, 12.5, 1, true)] + [InlineData(JetDataType.DateTime, 8, "2000-01-02", 1, true)] + public void An_explicit_value_in_a_fixed_column_flagged_AutoNumber_needs_four_bytes( + JetDataType type, int length, object value, int counter, bool refused) + { + string path = TemporaryDatabase.CreatePath("autonumber-fixed-"); + try + { + JetDatabase.Create(path); + int page; + byte[] raw; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("V", type, length, IsFixedLength: true)]); + var t = db.Catalog.FindTable("T")!; + page = t.DefinitionPage; + raw = t.FindColumn("V")!.RawDescriptor!; + } + + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + file[page * format.PageSize + at + format.ColumnFlagsOffset] |= (byte)ColumnFlags.AutoNumber; + File.WriteAllBytes(path, file); + + object stored = type switch + { + JetDataType.Currency => Convert.ToDecimal(value, System.Globalization.CultureInfo.InvariantCulture), + JetDataType.DateTime => DateTime.Parse((string)value, System.Globalization.CultureInfo.InvariantCulture), + _ => value, + }; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + Table table = db.OpenTable("T"); + Assert.True(table.Definition.FindColumn("V")!.IsAutoNumber); + if (refused) + { + var ex = Assert.Throws(() => table.Insert([1, stored])); + Assert.Contains("too small to accept", ex.Message, StringComparison.Ordinal); + Assert.Empty(table.Rows()); + } + else + { + table.Insert([1, stored]); + Assert.Equal([1, stored], table.Rows().Single()); + } + } + Assert.Equal(counter, TableDefinition.ReadLastAutoNumber(TestDatabases.ReadPage(path, page), format)); + } + finally { TemporaryDatabase.Delete(path); } + } + // Without 0x80 ACE will not evaluate a calculated column, whatever its expression: every read of it fails "This // calculated column contains an invalid expression" (measured by clearing the bit on a DAO-created [Qty]*2). [Fact] From 10a9dcf35d322261bb0d9adc05c7cad313db324d Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 9 Nov 2026 20:29:29 +0800 Subject: [PATCH 16/27] Widen the fuzz write workload, and give libFuzzer a dictionary After millions of executions the write target had stopped finding anything new: on a damaged file it only ever rewrote one row of each table. The first input byte still picks the seed by its remainder; its quotient now selects operations from MalformedFile.Operations, run on each user table after the row rewrite: a chained long value written and taken out again, two columns added and dropped, an index built and dropped, rows deleted by a statement that rolls back, a rename and back, and a drop. Each runs as one statement in a transaction of its own, a refusal rolling it back, as QueryEngine runs a writing statement. The patches keep their meaning, so earlier corpora and crashes still replay. database.dict holds the multi-byte values random mutation is slow to find for the patch-list input: the page numbers and offsets of the fields a reader steers by, and the type codes and flag bits they take. The README covers the workload, -use_value_profile and -dict (quoted in PowerShell), and merging old corpora into a fresh one. Co-Authored-By: Claude Opus 5.5 --- test/LibRed.Core.Fuzz/Program.cs | 6 +- test/LibRed.Core.Fuzz/README.md | 45 +++++++++++-- test/LibRed.Core.Fuzz/database.dict | 63 +++++++++++++++++++ test/LibRed.Shared/MalformedFile.cs | 98 ++++++++++++++++++++++++++++- 4 files changed, 204 insertions(+), 8 deletions(-) create mode 100644 test/LibRed.Core.Fuzz/database.dict diff --git a/test/LibRed.Core.Fuzz/Program.cs b/test/LibRed.Core.Fuzz/Program.cs index 0e4c3082..f182efee 100644 --- a/test/LibRed.Core.Fuzz/Program.cs +++ b/test/LibRed.Core.Fuzz/Program.cs @@ -95,7 +95,8 @@ private static int Replay(ReadOnlySpanAction target, string input) /// mutating a whole file spends nearly every mutation on row data. So the input is a patch list against one of /// a fixed set of good seed databases: [seed][page u16][offset u16][byte]…, each field reduced modulo /// what it indexes. Inputs stay a few bytes long, every one decodes to a database, and libFuzzer still learns -/// which patches reach new code. Unlike the sweep, page 0 and every offset are in range. +/// which patches reach new code. Unlike the sweep, page 0 and every offset are in range. The first byte's +/// quotient by the seed count is the write workload's operation flags (). /// internal sealed class DatabaseTarget { @@ -141,7 +142,8 @@ public void Run(ReadOnlySpan data) } File.WriteAllBytes(_path, bytes); - foreach ((_, Exception? leak) in MalformedFile.Exercise(_path, password, _write)) + // The rest of the first byte picks the write workload's operations, so a patch list keeps its meaning. + foreach ((_, Exception? leak) in MalformedFile.Exercise(_path, password, _write, operations: data[0] / _seeds.Length)) if (leak is not null) ExceptionDispatchInfo.Throw(leak); } diff --git a/test/LibRed.Core.Fuzz/README.md b/test/LibRed.Core.Fuzz/README.md index e8fe2dbb..c471ba5e 100644 --- a/test/LibRed.Core.Fuzz/README.md +++ b/test/LibRed.Core.Fuzz/README.md @@ -17,7 +17,7 @@ The sweep stays the regression guard; this is the search. Nothing here runs in C | `LIBRED_FUZZ_TARGET` | Input | What it drives | | --- | --- | --- | | `database` | a patch list (below) | open, catalog, every table's rows, every index's entries — `MalformedFile.Exercise` | -| `writes` | a patch list (below) | the same walk opened for writing: in each user table still listed, the first of its first 32 rows the write accepts is also rewritten in place, deleted and inserted again, before its indexes are walked | +| `writes` | a patch list (below) | the same walk opened for writing: in each user table still listed, the first of its first 32 rows the write accepts is also rewritten in place, deleted and inserted again, then the operations the input selects run (below), before its indexes are walked | | `properties` | raw bytes | `PropertyBlob.Read`, the `LvProp` blob decoder | | `namemap` | raw bytes | `NameMap.ReadRow` and `NameMap.ReadProperty` | @@ -35,6 +35,23 @@ treating them as leaks only buries the real findings: an out-of-range index, a n The cost is that damage which surfaces as `InvalidOperationException` goes unflagged here. The two targets take the same inputs, so `corpus\database` is a good starting corpus for `corpus\writes`. +**The first byte also picks the `writes` workload.** Its remainder by six is the seed; its quotient is a set of +flags, bit *n* selecting entry *n* of `MalformedFile.Operations`, run on every user table in this order: + +| Bit | Operation | What it reaches | +| --- | --- | --- | +| 0 | long values | a 9,000-byte value into every Memo and OLE column of the first row, then null: long-value chains allocated and freed | +| 1 | add and drop columns | a Long and a Text column added and dropped: four definition rewrites | +| 2 | create and drop an index | an index built from the table's rows over its first Long or Text column, then dropped | +| 3 | delete and roll back | the first 32 rows deleted by a statement that rolls back | +| 4 | rename and rename back | the table and its first column renamed and named back | +| 5 | drop the table | every page the table owns freed, then released at close | + +Each runs as one statement, in a transaction of its own that a refusal rolls back, as `QueryEngine` runs a writing +statement. A byte holds at most 42 as a quotient, so a single input reaches every operation alone and many of their +combinations, not all of them at once. An input written before the workload existed keeps its patches: it simply +runs the operations its first byte now selects after the row rewrite it always ran. + ## Running it You need the SharpFuzz instrumenter and the libFuzzer driver. Both are third-party downloads, not restored by the @@ -58,17 +75,37 @@ Then fuzz one target. libfuzzer-dotnet passes the child exactly one argument (th environment. The corpus directory may start empty; libFuzzer grows it. ```powershell -$env:LIBRED_FUZZ_TARGET = "database" -mkdir corpus\database +$env:LIBRED_FUZZ_TARGET = "writes" +mkdir corpus\writes libfuzzer-dotnet-windows.exe --target_path=dotnet --target_arg=fuzz-bin\LibRed.Core.Fuzz.dll ` - -timeout=10 -rss_limit_mb=4096 -max_len=256 corpus\database + -timeout=10 -rss_limit_mb=4096 -max_len=256 ` + -use_value_profile=1 "-dict=test\LibRed.Core.Fuzz\database.dict" corpus\writes ``` +The quotes matter in PowerShell: an argument that starts with `-` and contains a `.` is otherwise split at the dot, +and libFuzzer then takes `.Core.Fuzz\database.dict` for a corpus directory that does not exist. + +`-use_value_profile=1` makes libFuzzer count a comparison that got closer as new coverage, which is what gets a +patch past a check on one exact value — a type code, a flag bit, a page number. `database.dict` gives the mutator the +multi-byte values it is slow to guess at random: the u16 page numbers and offsets of the fields a reader steers by +(page 0's map pointers, the TDEF counters, a column descriptor's type and flags) and the values they take. Both apply +to `database` as well; the blob targets want neither. + `-max_len=256` is about 50 patches, plenty for `database`; the blob targets want more (`-max_len=4096`). Every `database` run copies and writes a seed file, so it is the slow target — `replay` gets through 300 random inputs in about four seconds, startup and authoring the seeds included, uninstrumented — and the blob targets are far faster. Add `-jobs=N -workers=N` to use more cores, `-max_total_time=` to stop on a budget. +**When a run stops finding anything, change what it is given rather than running it longer.** Merge what earlier +runs found into a fresh, minimal corpus — libFuzzer keeps only the inputs that still add coverage — and start the +next run from that: + +```powershell +mkdir corpus\merged +libfuzzer-dotnet-windows.exe --target_path=dotnet --target_arg=fuzz-bin\LibRed.Core.Fuzz.dll ` + -merge=1 -timeout=10 -rss_limit_mb=4096 corpus\merged corpus\writes corpus\database +``` + ## When it finds something libFuzzer stops and writes the input as `crash-` (or `timeout-…`, `oom-…`) in the current directory. diff --git a/test/LibRed.Core.Fuzz/database.dict b/test/LibRed.Core.Fuzz/database.dict new file mode 100644 index 00000000..91a962d6 --- /dev/null +++ b/test/LibRed.Core.Fuzz/database.dict @@ -0,0 +1,63 @@ +# libFuzzer dictionary for the database and writes targets (-dict=test\LibRed.Core.Fuzz\database.dict). +# +# The input is a patch list, [seed][page u16][offset u16][byte]..., so the entries that help are the ones random +# mutation is slow to find: little-endian u16 page numbers and in-page offsets of fields that steer a reader, and +# the byte values those fields take. Offsets are Jet 4 / ACE (src/LibRed/LibRed.Core/Formats/Jet4Format.cs). + +# Pages: the database definition, the global maps' holder, the first catalog pages. +page_0="\x00\x00" +page_1="\x01\x00" +page_2="\x02\x00" +page_3="\x03\x00" + +# Page 0: version byte, free-pages and released-pages map pointers. +p0_version="\x14\x00" +p0_free_map="\x18\x00" +p0_free_map_page="\x19\x00" +p0_released_map="\x1c\x00" +p0_released_map_page="\x1d\x00" + +# Data and TDEF page header: owner, row count; TDEF row count and AutoNumber counter. +data_owner="\x04\x00" +data_rows="\x0c\x00" +tdef_rows="\x10\x00" +tdef_autonumber="\x14\x00" + +# Patch bytes: boundaries, sign bits, and the column flag bits (fixed 0x01, updatable 0x02, AutoNumber 0x04, +# GUID 0x40, hyperlink 0x80) and extended flag bits (calculated 0x40, evaluate 0x80). +b_00="\x00" +b_01="\x01" +b_02="\x02" +b_04="\x04" +b_06="\x06" +b_40="\x40" +b_7f="\x7f" +b_80="\x80" +b_c0="\xc0" +b_ff="\xff" + +# Column type codes. +type_boolean="\x01" +type_byte="\x02" +type_int16="\x03" +type_int32="\x04" +type_currency="\x05" +type_single="\x06" +type_double="\x07" +type_datetime="\x08" +type_binary="\x09" +type_text="\x0a" +type_ole="\x0b" +type_memo="\x0c" +type_guid="\x0f" +type_numeric="\x10" +type_complex="\x12" +type_bigint="\x13" +type_datetime2="\x14" + +# Wide values for multi-byte fields (counts, pointers, start pages). +u16_max="\xff\xff" +u16_signed_max="\xff\x7f" +u16_signed_min="\x00\x80" +u32_max="\xff\xff\xff\xff" +u32_signed_min="\x00\x00\x00\x80" diff --git a/test/LibRed.Shared/MalformedFile.cs b/test/LibRed.Shared/MalformedFile.cs index 7b97084e..d54a3e02 100644 --- a/test/LibRed.Shared/MalformedFile.cs +++ b/test/LibRed.Shared/MalformedFile.cs @@ -114,13 +114,15 @@ private static string Author(string directory, string name, Action /// Walks everything a caller would, one stage at a time and continuing past failures: open, list /// the catalog, then each table's rows separately. With , in each user table still /// listed, the first of its first 32 rows the write accepts is also rewritten in place, deleted and inserted - /// again before its indexes are walked. + /// again, then each of the selects runs, before its + /// indexes are walked. /// /// /// Per-stage on purpose. Stopping at the first exception means one damaged TDEF hides every path behind /// it, and the interesting leak is rarely the first thing that breaks. /// - public static IEnumerable<(string Stage, Exception? Leak)> Exercise(string path, string? password = null, bool write = false) + public static IEnumerable<(string Stage, Exception? Leak)> Exercise(string path, string? password = null, bool write = false, + int operations = 0) { JetDatabase? database = null; try @@ -187,6 +189,18 @@ private static string Author(string directory, string name, Action if (!listed) continue; } + // Then the operations selected — the code a row rewrite never reaches: long-value chains, schema edits, + // a rolled-back transaction. Each is one statement, as QueryEngine runs every writing statement: in a + // transaction of its own, rolled back when the operation is refused. + for (int bit = 0; write && !table.IsSystem && listed && bit < Operations.Length; bit++) + { + if ((operations & (1 << bit)) == 0) continue; + (string name, Action operation, bool rollBack) = Operations[bit]; + yield return Try($"{name} '{table.Name}'", () => Statement(database, () => operation(database, table.Name), rollBack)); + yield return Try($"find '{table.Name}' again", () => listed = database.Catalog.FindTable(table.Name) is not null); + } + if (!listed) continue; + // A table SCAN reads the usage map and the data pages and never descends a B-tree, so // without this every index page the sweep corrupts goes unread — the split-index shape was // building node pages that nothing then looked at. Walking the entries decodes every page @@ -208,6 +222,86 @@ private static string Author(string directory, string name, Action finally { database?.Dispose(); } } + /// + /// What a write workload can run on each user table after its row rewrite, in this order; bit n of + /// 's operations selects entry n. Each uses only the public API, and none + /// leaves the schema changed on an undamaged file, so the walk after it reads what it read before — except the + /// last, which drops the table. + /// + internal static readonly (string Name, Action Run, bool RollBack)[] Operations = + [ + // A chained long value written into every Memo and OLE column of the first row, then taken out again: the + // long-value allocation and the free of a chain. + ("long values", (database, name) => + { + Table table = database.OpenTable(name); + List longValues = [.. table.Definition.Columns.Where(c => c.Type is JetDataType.Memo or JetDataType.Ole)]; + if (longValues.Count == 0 || table.Rows().WithIds().Take(1).ToList() is not [(RowId id, object?[] row)]) return; + var changed = (object?[])row.Clone(); + foreach (ColumnDef column in longValues) + changed[column.Index] = column.Type == JetDataType.Memo ? new string('m', 9000) : new byte[9000]; + table.Update(id, changed, longValues.Select(c => c.Index).ToHashSet()); + foreach (ColumnDef column in longValues) changed[column.Index] = null; + table.Update(id, changed, longValues.Select(c => c.Index).ToHashSet()); + }, false), + // Two columns added, one fixed and one variable, and dropped again: the definition rewritten four times. + ("add and drop columns", (database, name) => + { + database.AddColumn(name, new ColumnSpec("FuzzLong", JetDataType.Int32, 4, IsFixedLength: true)); + database.AddColumn(name, new ColumnSpec("FuzzText", JetDataType.Text, 40, IsFixedLength: false)); + database.DropColumn(name, "FuzzLong"); + database.DropColumn(name, "FuzzText"); + }, false), + // An index built over the table's rows and dropped again: a B-tree built from damaged rows, then freed. + ("create and drop an index", (database, name) => + { + if (database.OpenTable(name).Definition.Columns.FirstOrDefault(c => c.Type is JetDataType.Int32 or JetDataType.Text) + is not { } column) return; + database.CreateIndex(name, "FuzzIndex", [(column.Name, false)]); + database.DropIndex(name, "FuzzIndex"); + }, false), + // The first rows deleted by a statement that then rolls back: every page it wrote restored from the overlay. + ("delete and roll back", (database, name) => + { + Table table = database.OpenTable(name); + foreach ((RowId id, _) in table.Rows().WithIds().Take(32).ToList()) + { + try { table.Delete(id); } + catch (InvalidOperationException) { } + } + }, true), + // The table and its first column renamed and named back: the catalog row and the definition rewritten. + ("rename and rename back", (database, name) => + { + if (database.RenameTable(name, "FuzzRenamed")) database.RenameTable("FuzzRenamed", name); + string column = database.OpenTable(name).Definition.Columns[0].Name; + if (database.RenameColumn(name, column, "FuzzColumn")) database.RenameColumn(name, "FuzzColumn", column); + }, false), + // The table dropped: every page it owns freed, then released at close. + ("drop the table", (database, name) => database.DropTable(name), false), + ]; + + /// Runs as one statement: in a transaction of its own, committed — or, with + /// , rolled back — or rolled back when the operation is refused with + /// , as ACE refuses a write a damaged schema breaks. Anything else rolls + /// back too and goes on to be judged by the contract. + private static void Statement(JetDatabase database, Action operation, bool rollBack) + { + database.BeginTransaction(); + try + { + operation(); + if (rollBack) database.Rollback(); + else database.Commit(flush: false); + } + catch (InvalidOperationException) { database.Rollback(failed: true); } + catch + { + database.Rollback(failed: true); + throw; + } + } + private static (string Outcome, Exception? Leak) Try(string stage, Action action) { try From 999beeec761973ba2fe44929a6e83a6da78bc34f Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 9 Nov 2026 20:29:39 +0800 Subject: [PATCH 17/27] Refuse the relationships when an MSysRelationships column has another type LoadRelationships casts each MSysRelationships value to the type its column should have. With a type byte damaged (szColumn's made 0x0D, a code no type has) the value decodes as bytes, and the cast threw InvalidCastException out of DropIndex's relationship lookup. Measured against ACE on that damage, the foreign-key list fails "Cannot perform this operation" while every table still lists and reads and unrelated DDL runs. LoadRelationships now refuses with InvalidDataException when a column it reads is not its spec's type; the table list is untouched. Co-Authored-By: Claude Opus 5.5 --- src/LibRed/LibRed.Core/Catalog/JetCatalog.cs | 6 ++++ src/LibRed/docs/format/page-02b-columns.md | 2 +- test/LibRed.Core.Tests/CatalogTests.cs | 34 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs b/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs index 8ba1ae1a..2eb62800 100644 --- a/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs +++ b/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs @@ -983,6 +983,12 @@ private IReadOnlyList LoadRelationships(string? keyColumn = null, st } } + // Every column below is read as its own type. One of another type — a damaged type byte — leaves no + // relationship readable, as ACE's foreign-key list fails "Cannot perform this operation" on it while every + // table still reads (measured, MSysRelationships.szColumn's type byte made 0x0D). + if (MSysRelationshipsColumns.FirstOrDefault(c => def.FindColumn(c.Name)?.Type != c.Type) is { } retyped) + throw new InvalidDataException( + $"MSysRelationships.{retyped.Name} is not {retyped.Type}: the relationships cannot be read."); var catalogRows = new CatalogRows(_channel, def); var columns = def.Columns.ToDictionary(c => c.Name, c => c.Index, StringComparer.OrdinalIgnoreCase); int nameIdx = columns["szRelationship"], childTableIdx = columns["szObject"], childColumnIdx = columns["szColumn"], diff --git a/src/LibRed/docs/format/page-02b-columns.md b/src/LibRed/docs/format/page-02b-columns.md index 8add3852..9f3af419 100644 --- a/src/LibRed/docs/format/page-02b-columns.md +++ b/src/LibRed/docs/format/page-02b-columns.md @@ -6,7 +6,7 @@ | Offset | Size | Meaning | | --- | --- | --- | -| `0x00` | 1 | Data type (see §6) | +| `0x00` | 1 | Data type (see §6). A code no type has does not refuse the table outright (verified): with `0x0D` or `0x0E` the table opens and counts, and only a read of that column fails — OLE DB's conversion errors, or *"Data type mismatch in criteria expression"* in a `WHERE`; with `0x15` everything that loads the table is *"Unrecognized database format"*. On `MSysRelationships.szColumn` (`0x0D`) every table still lists and reads and unrelated DDL runs, but the foreign-key list fails *"Cannot perform this operation"*; LibRed refuses reading the relationships the same way | | `0x01` | 2 | Minimum engine build for the column, the low half of a 32-bit value (`0x03` is the high half) — `0x0659` as ACE and Jet 4.0 write it; each refuses the table when it exceeds its own build, 4518 and 9801 ([page-02a §3.1](page-02a-tdef.md) note) | | `0x03` | 2 | The high half of the minimum-build field at `0x01`, which is 32 bits: non-zero here puts the build past ACE's, and ACE refuses the table — *"This object requires a newer version of the Microsoft Access database engine"* (verified). Write zero | | `0x05` | 2 | Column id | diff --git a/test/LibRed.Core.Tests/CatalogTests.cs b/test/LibRed.Core.Tests/CatalogTests.cs index fa85ce02..25042a57 100644 --- a/test/LibRed.Core.Tests/CatalogTests.cs +++ b/test/LibRed.Core.Tests/CatalogTests.cs @@ -40,4 +40,38 @@ public void Resolves_full_column_lists() Assert.Equal(14, db.Catalog.FindTable("Orders")!.Columns.Count); } + + // MSysRelationships.szColumn's type byte damaged from Text (0x0A) to 0x0D, a code no type has. The catalog reads + // that column as text and cannot, so the relationships are refused while every table still reads — as ACE + // refuses its foreign-key list on this damage ("Cannot perform this operation") and reads the tables (measured). + [Fact] + public void A_catalog_column_of_another_type_refuses_that_catalog_table_only() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "catalog-type-"); + try + { + int page, userTables; + byte[] raw; + using (var db = JetDatabase.Open(path)) + { + userTables = db.Catalog.UserTables.Count(); + Catalog.TableDefinition relationships = db.Catalog.FindTable("MSysRelationships")!; + page = relationships.DefinitionPage; + raw = relationships.FindColumn("szColumn")!.RawDescriptor!; + } + byte[] file = File.ReadAllBytes(path); + Formats.JetFormatBase format = Formats.JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + Assert.Equal((byte)Catalog.JetDataType.Text, file[page * format.PageSize + at + format.ColumnTypeOffset]); + file[page * format.PageSize + at + format.ColumnTypeOffset] = 0x0D; + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path); + Assert.Throws(() => damaged.Catalog.Relationships); + Assert.Equal(91, damaged.OpenTable("Customers").Rows().Count()); + Assert.Equal(userTables, damaged.Catalog.UserTables.Count()); + } + finally { TemporaryDatabase.Delete(path); } + } } From 5c18deeaa5ea6788a27df667232afb4afb7b17c0 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 9 Nov 2026 20:29:47 +0800 Subject: [PATCH 18/27] Validate the usage-map page CREATE INDEX appends to, as every read does CREATE INDEX appends the new index's usage map to the page holding the table's own maps, and AppendEmptyUsageMapRow read that page raw. With its row count damaged past what a page holds, TryAppendRow walked the slot directory off the end of the page and threw ArgumentOutOfRangeException. It now parses the page with DataPage.Read first, as LongValueStore's append does, so the page is refused as InvalidDataException exactly as every read of it already refuses it. Co-Authored-By: Claude Opus 5.5 --- .../LibRed.Core/Catalog/SchemaEditor.cs | 6 ++++- .../PageAndRowCorruptionTests.cs | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs b/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs index aa74541a..7b76a85b 100644 --- a/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs +++ b/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs @@ -957,7 +957,11 @@ private void SetBuiltStatistics(TableDefinition table, IndexDef index, List<(byt /// record, and returns its row. The new map tracks no pages yet, so an empty bitmap is correct. private int AppendEmptyUsageMapRow(JetFormatBase format, int pageNumber) { - byte[] page = _channel.ReadPage(pageNumber).Span.ToArray(); + // Read as every other append reads its page first: the header and the slot directory checked, so a page + // whose row count runs past it is refused rather than walked. + PageBuffer buffer = _channel.ReadPage(pageNumber); + new DataPage().Read(buffer, format); + byte[] page = buffer.Span.ToArray(); // A record written below the directory would overwrite the slots themselves — which reads back later // as a slot with offset 0 "outside the row heap", a long way from the cause. The caller is expected diff --git a/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs b/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs index 0bebc525..d8f74f94 100644 --- a/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs +++ b/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs @@ -64,6 +64,33 @@ public void Direct_row_seek_applies_the_same_slot_validation() DataPage.TryReadRow(new PageBuffer(page, 7), Format, 1, out _, out _)); } + // CREATE INDEX appends the new index's usage map to the page holding the table's own maps when it has room. That + // page's row count pushed past what a page holds is refused there as on every read of it, not walked off the + // page's end. + [Fact] + public void Creating_an_index_applies_the_same_header_validation_to_the_usage_map_page() + { + string path = TemporaryDatabase.CreatePath("index-mappage-"); + try + { + JetDatabase.Create(path); + int mapPage; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("A", JetDataType.Text, 40, IsFixedLength: false)]); + mapPage = db.Channel.ReadPage(db.Catalog.FindTable("T")!.DefinitionPage).ReadRecordPointer(Format.TdefOwnedPagesOffset).Page; + } + byte[] page = TestDatabases.ReadPage(path, mapPage); + BinaryPrimitives.WriteUInt16LittleEndian(page.AsSpan(Format.DataRowCountOffset, 2), + (ushort)(BinaryPrimitives.ReadUInt16LittleEndian(page.AsSpan(Format.DataRowCountOffset, 2)) | 0x4500)); + TestDatabases.WritePage(path, mapPage, page); + + using var damaged = JetDatabase.Open(path, readOnly: false); + Assert.Throws(() => damaged.CreateIndex("T", "ix", [("A", false)])); + } + finally { TemporaryDatabase.Delete(path); } + } + [Fact] public void Zero_length_deleted_overflow_tombstone_remains_a_valid_slot_shape() { From 11be4b881e5dd0541d5f93403772f8d0db5b1d81 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 9 Nov 2026 21:01:02 +0800 Subject: [PATCH 19/27] Read a null in a relationship row as ACE does, instead of throwing LoadRelationships cast every MSysRelationships column straight to its type, so one null (a cleared null-bitmap bit) threw ArgumentNullException or NullReferenceException out of Catalog.Relationships, and with it out of DROP COLUMN's relationship check. ACE, measured with one column of one row made null, leaves the relationship out of its foreign-key list when szObject or szReferencedObject is null and lists it all the same when szRelationship, szColumn, grbit or icolumn is. LibRed now does the same, reading a missing name or column as empty and missing flags or order as zero. Co-Authored-By: Claude Opus 5.5 --- src/LibRed/LibRed.Core/Catalog/JetCatalog.cs | 12 ++++-- src/LibRed/docs/format/system-catalog.md | 7 ++++ test/LibRed.Core.Tests/CatalogTests.cs | 40 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs b/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs index 2eb62800..858b232d 100644 --- a/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs +++ b/src/LibRed/LibRed.Core/Catalog/JetCatalog.cs @@ -1009,14 +1009,18 @@ private IReadOnlyList LoadRelationships(string? keyColumn = null, st r => string.Equals(r[keyIdx] as string, key, StringComparison.OrdinalIgnoreCase)).Select(r => r.Values); foreach (object?[] row in rows) { - string name = (string)row[nameIdx]!; + // A null where a value belongs, as ACE reads it (measured, one row's column made NULL): a row naming no + // child or parent table is left out of the foreign-key list; a null name, flags, column order or column + // is listed all the same, as empty and zero. + if (row[childTableIdx] is not string childTable || row[parentTableIdx] is not string parentTable) continue; + string name = row[nameIdx] as string ?? ""; if (!groups.TryGetValue(name, out var g)) { - g = ((string)row[childTableIdx]!, (string)row[parentTableIdx]!, - (RelationshipFlags)(int)row[flagsIdx]!, []); + g = (childTable, parentTable, (RelationshipFlags)(row[flagsIdx] as int? ?? 0), []); groups[name] = g; } - g.Columns.Add(((int)row[orderIdx]!, (string)row[childColumnIdx]!, (string)row[parentColumnIdx]!)); + g.Columns.Add((row[orderIdx] as int? ?? 0, row[childColumnIdx] as string ?? "", + row[parentColumnIdx] as string ?? "")); } IReadOnlyList result = groups diff --git a/src/LibRed/docs/format/system-catalog.md b/src/LibRed/docs/format/system-catalog.md index 72c90318..79f29dfa 100644 --- a/src/LibRed/docs/format/system-catalog.md +++ b/src/LibRed/docs/format/system-catalog.md @@ -844,6 +844,13 @@ single-column FK stores `ccolumn = 1`, `icolumn = 0`, `grbit = 0`; a relationship cascading both update and delete stores `grbit = 0x1100`; Access's relationship dialog writes each bit above as its option says. + > **A relationship row with a null column** (measured, by clearing one column's null-bitmap bit in one row). The + > database opens, every table reads and DDL runs. The foreign-key list leaves out the relationship whose row has + > a null `szObject` or `szReferencedObject`, and lists it all the same with a null `szRelationship`, `szColumn`, + > `icolumn` or `grbit`. LibRed reads the relationships the same way. A column of another type than its own — a + > damaged type byte — fails the foreign-key list instead, *"Cannot perform this operation"*, and LibRed refuses + > the relationships as `InvalidDataException` ([page-02b §3.4](page-02b-columns.md)). + > **`grbit` records the relationship; ACE does not act on its cascade bits.** The update and delete actions > ACE applies are the ones in the relationship's index-info blocks (§3.6, `0x15`/`0x16`): with the two made > to disagree, a parent delete that `grbit` calls cascading but the blocks do not is refused, and one the diff --git a/test/LibRed.Core.Tests/CatalogTests.cs b/test/LibRed.Core.Tests/CatalogTests.cs index 25042a57..a7e84ba8 100644 --- a/test/LibRed.Core.Tests/CatalogTests.cs +++ b/test/LibRed.Core.Tests/CatalogTests.cs @@ -74,4 +74,44 @@ public void A_catalog_column_of_another_type_refuses_that_catalog_table_only() } finally { TemporaryDatabase.Delete(path); } } + + // One MSysRelationships row with one column made NULL through its null bitmap. ACE's foreign-key list leaves out + // the relationship whose row names no child or parent table, and lists it all the same with a null name, flags, + // column order or column (measured on this file's first row, FK_CustomerCustomerDemo: 14 and 15 of 15). + [Theory] + [InlineData("szObject", true)] + [InlineData("szReferencedObject", true)] + [InlineData("szRelationship", false)] + [InlineData("grbit", false)] + [InlineData("icolumn", false)] + [InlineData("szColumn", false)] + public void A_null_in_a_relationship_row_leaves_it_out_only_when_it_names_no_table(string column, bool leftOut) + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "catalog-relnull-"); + try + { + int offset, bit, relationships; + using (var db = JetDatabase.Open(path)) + { + relationships = db.Catalog.Relationships.Count; + Storage.Table rel = db.OpenTable("MSysRelationships"); + int columnId = rel.Definition.FindColumn(column)!.ColumnId; + var (id, _) = rel.Rows().WithIds().First(); + Formats.JetFormatBase format = db.Channel.Format; + Assert.True(Pages.DataPage.TryReadRow(db.Channel.ReadPage(id.Page), format, id.Row, + out Pages.DataPage.RowSlot slot, out ReadOnlySpan row)); + int bitmapSize = Storage.BitmapBits.ByteCount(System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(row)); + offset = id.Page * format.PageSize + slot.Offset + slot.Length - bitmapSize + (columnId >> 3); + bit = 1 << (columnId & 7); + } + byte[] bytes = File.ReadAllBytes(path); + Assert.NotEqual(0, bytes[offset] & bit); + bytes[offset] &= (byte)~bit; + File.WriteAllBytes(path, bytes); + + using var damaged = JetDatabase.Open(path); + Assert.Equal(leftOut ? relationships - 1 : relationships, damaged.Catalog.Relationships.Count); + } + finally { TemporaryDatabase.Delete(path); } + } } From 899a8de73ddf2d9bbf3a91160bca453b38a2467c Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Tue, 10 Nov 2026 00:48:41 +0800 Subject: [PATCH 20/27] Rename back in the fuzz workload only a name a caller could give A damaged file can store a column name ACE's DDL refuses, a control character in it. ACE reads such a name as stored, and once the column is renamed away it refuses to give the name back: "is not a valid name" (measured through DAO). LibRed does the same. The workload's rename round trip passed the stored name back in as a caller's argument, so LibRed's refusal of it surfaced as an ArgumentException leak. The round trip now runs only on a name JetName.Validate accepts. A new test pins the measured behaviour on both engines, and the TDEF spec records it. Co-Authored-By: Claude Opus 5.5 --- src/LibRed/docs/format/page-02a-tdef.md | 4 +++ .../RenameNameValidationAccessTests.cs | 33 +++++++++++++++++++ test/LibRed.Shared/MalformedFile.cs | 15 +++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/LibRed/docs/format/page-02a-tdef.md b/src/LibRed/docs/format/page-02a-tdef.md index b9e3b6b6..615ccf21 100644 --- a/src/LibRed/docs/format/page-02a-tdef.md +++ b/src/LibRed/docs/format/page-02a-tdef.md @@ -306,6 +306,10 @@ the documented 255-column, 32-index, and 64-character-name limits. > FOREIGN KEY` is refused when the table already has an index of that name — *"Table 'FkC' already has an index > named 'Taken'."* > +> A stored column name that holds a control character (U+0003, verified) still reads: the table opens and +> `SELECT *` names the column as stored. Only the DDL refuses it, so a column renamed away from that name (DAO's +> `Field.Name`) cannot be given it back — *"'…' is not a valid name."* +> > LibRed enforces all of this on caller-supplied names via `JetName.Validate`, since writing the format > directly bypasses ACE's DDL parser. Internal hidden names (the `.rN` incoming-relationship index names, §3.6) > legitimately start with `.` and are **not** validated. diff --git a/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs b/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs index f5373efd..1f1782cd 100644 --- a/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs +++ b/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs @@ -185,6 +185,39 @@ public void Refusing_the_rename_leaves_a_database_ace_can_still_open() Assert.Equal("hello", read.ExecuteScalar()); } + // A damaged file can hold a name ACE's DDL refuses — here SupplierID's 'r' made U+0003. ACE reads it as stored: + // the table opens and SELECT * names the column so. Renamed away through DAO, it cannot be given back: "'…' is + // not a valid name" (measured). LibRed reads it the same way and refuses the rename back as it refuses the name + // from any caller. + [Fact] + public void A_stored_name_create_would_refuse_still_reads_but_cannot_be_given_back() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "rename-stored-name-"); + string damaged = "Supplie" + (char)3 + "ID"; + int page; + using (var database = JetDatabase.Open(path)) page = database.Catalog.FindTable("Suppliers")!.DefinitionPage; + byte[] file = File.ReadAllBytes(path); + int pageSize = Formats.JetFormatBase.FromVersionByte(file[0x14]).PageSize; + int at = file.AsSpan(page * pageSize, pageSize).IndexOf(System.Text.Encoding.Unicode.GetBytes("SupplierID")); + Assert.True(at >= 0); + System.Text.Encoding.Unicode.GetBytes(damaged).CopyTo(file, page * pageSize + at); + File.WriteAllBytes(path, file); + + using (OleDbConnection connection = AceTestDatabase.Open(path)) + using (OleDbCommand read = connection.CreateCommand()) + { + read.CommandText = "SELECT * FROM Suppliers"; + using OleDbDataReader reader = read.ExecuteReader(); + Assert.Equal(damaged, reader.GetName(0)); + } + + using var libred = JetDatabase.Open(path, readOnly: false); + Assert.Equal(damaged, libred.Catalog.FindTable("Suppliers")!.Columns[0].Name); + Assert.Equal(29, libred.OpenTable("Suppliers").Rows().Count()); + Assert.True(libred.RenameColumn("Suppliers", damaged, "Renamed")); + Assert.Throws(() => libred.RenameColumn("Suppliers", "Renamed", damaged)); + } + private static JetDatabase Fresh(out string path) { path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "rename-name-"); diff --git a/test/LibRed.Shared/MalformedFile.cs b/test/LibRed.Shared/MalformedFile.cs index d54a3e02..e0aabe73 100644 --- a/test/LibRed.Shared/MalformedFile.cs +++ b/test/LibRed.Shared/MalformedFile.cs @@ -270,17 +270,26 @@ internal static readonly (string Name, Action Run, bool Rol catch (InvalidOperationException) { } } }, true), - // The table and its first column renamed and named back: the catalog row and the definition rewritten. + // The table and its first column renamed and named back: the catalog row and the definition rewritten. Only a + // name a caller could give is named back: damage can store one ACE refuses, which reads but cannot be given + // back, there or here. ("rename and rename back", (database, name) => { - if (database.RenameTable(name, "FuzzRenamed")) database.RenameTable("FuzzRenamed", name); + if (Nameable(name) && database.RenameTable(name, "FuzzRenamed")) database.RenameTable("FuzzRenamed", name); string column = database.OpenTable(name).Definition.Columns[0].Name; - if (database.RenameColumn(name, column, "FuzzColumn")) database.RenameColumn(name, "FuzzColumn", column); + if (Nameable(column) && database.RenameColumn(name, column, "FuzzColumn")) + database.RenameColumn(name, "FuzzColumn", column); }, false), // The table dropped: every page it owns freed, then released at close. ("drop the table", (database, name) => database.DropTable(name), false), ]; + private static bool Nameable(string name) + { + try { JetName.Validate(name); return true; } + catch (ArgumentException) { return false; } + } + /// Runs as one statement: in a transaction of its own, committed — or, with /// , rolled back — or rolled back when the operation is refused with /// , as ACE refuses a write a damaged schema breaks. Anything else rolls From 9072af30bda49cafe5cafe24ee7b5c2b4001887d Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Tue, 10 Nov 2026 23:40:17 +0800 Subject: [PATCH 21/27] Resolve an index column by name as ACE does when two columns share it ResolveSlots built a dictionary of every column in the table to look up the index's columns, so a definition whose damage gave two columns one name threw ArgumentException out of CREATE INDEX and ADD FOREIGN KEY, whichever column was asked for. ACE reads such a table, resolves the name to the first column that has it, and creates an index over that name or any other (measured). ResolveSlots now looks each column up with TableDefinition.FindColumn, the first-match lookup every other by-name read already uses. Co-Authored-By: Claude Opus 5.5 --- .../LibRed.Core/Catalog/SchemaEditor.cs | 10 +++--- src/LibRed/docs/format/page-02a-tdef.md | 5 +++ test/LibRed.Core.Tests/CatalogTests.cs | 34 +++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs b/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs index 7b76a85b..2c87297c 100644 --- a/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs +++ b/src/LibRed/LibRed.Core/Catalog/SchemaEditor.cs @@ -731,14 +731,12 @@ private static void RejectOleIndexColumns(IEnumerable columnNames, Func< throw new InvalidOperationException($"Invalid field definition '{name}' in definition of index or relationship."); } - /// Resolves index column names to (columnId, ascending) slots against a table. + /// Resolves index column names to (columnId, ascending) slots against a table. A name two columns of a + /// damaged definition share resolves to the first of them, as ACE resolves it (measured). private static List<(int Id, bool Ascending)> ResolveSlots( - TableDefinition table, IEnumerable<(string Column, bool Ascending)> columns) - { - var byName = table.Columns.ToDictionary(c => c.Name, c => c.ColumnId, StringComparer.OrdinalIgnoreCase); - return columns.Select(c => byName.TryGetValue(c.Column, out int id) ? (Id: id, c.Ascending) + TableDefinition table, IEnumerable<(string Column, bool Ascending)> columns) => + columns.Select(c => table.FindColumn(c.Column) is { } column ? (Id: column.ColumnId, c.Ascending) : throw new InvalidOperationException($"Column '{c.Column}' does not exist in '{table.Name}'.")).ToList(); - } /// ACE rejects a duplicate index name — for a foreign key's backing index as much as a CREATE INDEX, and /// for a rename (verified) — and so must LibRed: every lookup downstream (DROP INDEX, the back-fill, DROP diff --git a/src/LibRed/docs/format/page-02a-tdef.md b/src/LibRed/docs/format/page-02a-tdef.md index 615ccf21..a5b30916 100644 --- a/src/LibRed/docs/format/page-02a-tdef.md +++ b/src/LibRed/docs/format/page-02a-tdef.md @@ -310,6 +310,11 @@ the documented 255-column, 32-index, and 64-character-name limits. > `SELECT *` names the column as stored. Only the DDL refuses it, so a column renamed away from that name (DAO's > `Field.Name`) cannot be given it back — *"'…' is not a valid name."* > +> Two columns stored under one name (verified, one name entry damaged into another's) still read. A lookup by +> that name resolves to the first of them: `SELECT` of the name reads the first column's value, `SELECT *` lists +> both as `Table.name`, and `CREATE INDEX` over the name indexes the first. `ADD COLUMN` of the name is refused, +> *"Field '…' already exists in table '…'."* +> > LibRed enforces all of this on caller-supplied names via `JetName.Validate`, since writing the format > directly bypasses ACE's DDL parser. Internal hidden names (the `.rN` incoming-relationship index names, §3.6) > legitimately start with `.` and are **not** validated. diff --git a/test/LibRed.Core.Tests/CatalogTests.cs b/test/LibRed.Core.Tests/CatalogTests.cs index a7e84ba8..512416ec 100644 --- a/test/LibRed.Core.Tests/CatalogTests.cs +++ b/test/LibRed.Core.Tests/CatalogTests.cs @@ -75,6 +75,40 @@ public void A_catalog_column_of_another_type_refuses_that_catalog_table_only() finally { TemporaryDatabase.Delete(path); } } + // One column's name damaged into another's: c4 made c3. ACE reads the table and resolves the name to the first + // column that has it — SELECT c3 reads c3's value — and CREATE INDEX succeeds over that name and over another + // column (measured on this shape). + [Fact] + public void A_name_two_columns_share_resolves_to_the_first_of_them() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "catalog-dupname-"); + try + { + int page; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("Wide", + [.. Enumerable.Range(0, 6).Select(i => new Catalog.ColumnSpec($"c{i}", Catalog.JetDataType.Int32, 4, IsFixedLength: true))]); + db.OpenTable("Wide").Insert([0, 1, 2, 3, 4, 5]); + page = db.Catalog.FindTable("Wide")!.DefinitionPage; + } + byte[] file = File.ReadAllBytes(path); + int pageSize = Formats.JetFormatBase.FromVersionByte(file[0x14]).PageSize; + // c4's name entry: its length, then the name in UTF-16. + int at = file.AsSpan(page * pageSize, pageSize).IndexOf((byte[])[4, 0, (byte)'c', 0, (byte)'4', 0]); + Assert.True(at >= 0); + file[page * pageSize + at + 4] = (byte)'3'; + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path, readOnly: false); + Assert.Equal(["c0", "c1", "c2", "c3", "c3", "c5"], damaged.Catalog.FindTable("Wide")!.Columns.Select(c => c.Name)); + damaged.CreateIndex("Wide", "I0", [("c0", false)]); + damaged.CreateIndex("Wide", "I3", [("c3", false)]); + Assert.Equal(3, damaged.Catalog.FindTable("Wide")!.FindIndex("I3")!.Columns.Single().Column.ColumnId); + } + finally { TemporaryDatabase.Delete(path); } + } + // One MSysRelationships row with one column made NULL through its null bitmap. ACE's foreign-key list leaves out // the relationship whose row names no child or parent table, and lists it all the same with a null name, flags, // column order or column (measured on this file's first row, FK_CustomerCustomerDemo: 14 and 15 of 15). From 5fcd952584c1d2ad430016baa86f38ee477ab141 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 11 Nov 2026 00:17:30 +0800 Subject: [PATCH 22/27] Skip the Croatian-stamped database query on the ACE 2016 redistributable Since the move to .NET 11 RC 3, the 2016 redistributable takes an access violation in ACECORE on the literal 'lja' < 'lm' in a database stamped Croatian. The fault ends the test process, so every LibRed.Core.AccessTests test after this one went unrun on that leg while the step still reported no failures. The Microsoft 365 runtime runs the query, so the test keeps running there; DATETIME2 support is how the suite tells the two apart. Co-Authored-By: Claude Opus 5.5 --- test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs b/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs index a356142a..512a1ec8 100644 --- a/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs +++ b/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs @@ -36,9 +36,15 @@ public void A_column_stamped_croatian_in_a_general_database_compares_as_general( AssertComparesIn(ace, GeneralOrder, below: ["ča", "ca"], literal: "general", minMax: "ca / lm"); } + // The 2016 redistributable takes an access violation in ACECORE on the literal 'lja' < 'lm' here, which kills the + // test process and every test after it; it answered on .NET 11 RC 2 and crashes since RC 3. DATETIME2 support is + // how this suite tells that engine from the Microsoft 365 runtime, which runs the query. [Fact] public void A_general_column_in_a_database_stamped_croatian_compares_as_croatian() { + Assert.SkipUnless(AceTestDatabase.SupportsColumnType(TestDatabases.NorthwindAccdb, "DATETIME2"), + "The ACE 2016 redistributable crashes (access violation in ACECORE) comparing a Croatian digraph literal " + + "in a database stamped Croatian."); Dictionary ace = Probe(stampHeader: true, stampColumn: false); AssertComparesIn(ace, CroatianOrder, below: ["ca"], literal: "croatian", minMax: "ca / lja"); } From ebaabf35e0c895bfe5815185fa65d77ddcda1cef Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 11 Nov 2026 00:43:33 +0800 Subject: [PATCH 23/27] Update to .NET 11 and EF Core 11 EF Core 11's specification tests need xunit.v3 4.0.1, so the xunit.v3 packages move with it, kept on the build EF resolves. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- CLAUDE.md | 2 +- Directory.Packages.props | 12 ++++++------ global.json | 2 +- .../Query/AdHocQueryFiltersQueryJetTest.cs | 14 -------------- .../Query/AdHocQueryFiltersQueryLibRedTest.cs | 14 -------------- .../Query/AdHocQueryFiltersQueryLibRedTest.cs | 14 -------------- 7 files changed, 9 insertions(+), 51 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index d84e7b82..f45d7bf5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ It is kept in sync with `CLAUDE.md`; if you change guidance in one, check whethe EntityFrameworkCore.Jet is an EF Core provider for Microsoft Jet/ACE databases (Microsoft Access `.mdb`/`.accdb` files). The **Jet** provider runs **Windows only** and bridges EF Core to the Access database engine via either ODBC or OLE DB. Alongside it, **LibRed** (also in this repo, on `master`) is a from-scratch managed engine that reads/writes the file format directly and is **cross-platform** — see the LibRed section below. -Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC3 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. +Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. `LibRed.Core`, `LibRed.Sql`, `LibRed.Engine` and `LibRed.Ado` are the exception: they multi-target `$(LibRedTargetFrameworks)` = `net10.0;net11.0`, since none of them depends on an EF Core package. `LibRed.EFCore` diff --git a/CLAUDE.md b/CLAUDE.md index 30ca5af4..2b937041 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co EntityFrameworkCore.Jet is an EF Core provider for Microsoft Jet/ACE databases (Microsoft Access `.mdb`/`.accdb` files). The **Jet** provider runs **Windows only** and bridges EF Core to the Access database engine via either ODBC or OLE DB. Alongside it, **LibRed** (also in this repo, on `master`) is a from-scratch managed engine that reads/writes the file format directly and is **cross-platform** — see the LibRed section below. -Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC3 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. +Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. **One exception to `net11.0`:** `LibRed.Core`, `LibRed.Sql`, `LibRed.Engine` and `LibRed.Ado` multi-target `$(LibRedTargetFrameworks)` = `net10.0;net11.0`, because none of them depends on an EF Core package. `LibRed.EFCore` diff --git a/Directory.Packages.props b/Directory.Packages.props index 69d802d7..b903c0ca 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,8 +1,8 @@ true - [11.0.0-rc.3.26522.148] - [11.0.0-rc.3.26522.148] + [11.0.0] + [11.0.0] @@ -25,7 +25,7 @@ - + @@ -41,8 +41,8 @@ xunit.v3.extensibility.core, so inheriting from its test bases requires v3. Pinned to the same build EF resolves, so the two cannot disagree about which xunit is in the graph. --> - - - + + + diff --git a/global.json b/global.json index 7a7a7d6e..02247fa2 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "11.0.100-rc.3.26522.148", + "version": "11.0.100", "allowPrerelease": true, "rollForward": "latestFeature" } diff --git a/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs index 94ca63bd..57a085f0 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs @@ -509,20 +509,6 @@ public override async Task Named_query_filters_combined() AssertSql(); } - public override async Task Query_filter_with_EF_Constant_throws() - { - await base.Query_filter_with_EF_Constant_throws(); - - AssertSql(); - } - - public override async Task Query_filter_with_EF_Parameter_throws() - { - await base.Query_filter_with_EF_Parameter_throws(); - - AssertSql(); - } - public override async Task GroupBy_aggregate_over_required_navigation_with_query_filter(bool async) { await base.GroupBy_aggregate_over_required_navigation_with_query_filter(async); diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs index c6169e1e..38eb490b 100644 --- a/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs @@ -511,20 +511,6 @@ public override async Task Named_query_filters_combined() AssertSql(); } - public override async Task Query_filter_with_EF_Constant_throws() - { - await base.Query_filter_with_EF_Constant_throws(); - - AssertSql(); - } - - public override async Task Query_filter_with_EF_Parameter_throws() - { - await base.Query_filter_with_EF_Parameter_throws(); - - AssertSql(); - } - public override async Task GroupBy_aggregate_over_required_navigation_with_query_filter(bool async) { await base.GroupBy_aggregate_over_required_navigation_with_query_filter(async); diff --git a/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs index 782c2345..eb0b1dc4 100644 --- a/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs +++ b/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs @@ -509,20 +509,6 @@ public override async Task Named_query_filters_combined() AssertSql(); } - public override async Task Query_filter_with_EF_Constant_throws() - { - await base.Query_filter_with_EF_Constant_throws(); - - AssertSql(); - } - - public override async Task Query_filter_with_EF_Parameter_throws() - { - await base.Query_filter_with_EF_Parameter_throws(); - - AssertSql(); - } - public override async Task GroupBy_aggregate_over_required_navigation_with_query_filter(bool async) { await base.GroupBy_aggregate_over_required_navigation_with_query_filter(async); From ab6ca1f636b8f58c57821b1bb4ed9d63c856aa84 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 11 Nov 2026 02:06:39 +0800 Subject: [PATCH 24/27] Bind long strings and binary as long types over ODBC The Access ODBC driver refuses a string parameter longer than 255 characters, and a binary one longer than 510 bytes, with HY104 "Invalid precision value", whatever the column, so saving or comparing a long value in a memo or long binary column failed (#306). Bound as long text or long binary the same values store and compare, and a value too big for its column gets ACE's "field is too small", as on OLE DB (measured). The string and byte-array mappings already mark such a value unbounded (Size -1); on ODBC they now also set OdbcType.NText or OdbcType.Image, through the set_OdbcType lookup the long and decimal mappings use. A JSON document goes through JetJsonTypeMapping, which had no ConfigureParameter and failed the same way past 255 characters, so it gets one. OLE DB takes long values as they are and is left unchanged. Co-Authored-By: Claude Opus 5.5 --- .../Internal/JetByteArrayTypeMapping.cs | 8 ++ .../Storage/Internal/JetJsonTypeMapping.cs | 19 +++++ .../Storage/Internal/JetStringTypeMapping.cs | 8 ++ .../Model80_LongValuesOverOdbc/Context.cs | 27 ++++++ .../Model80_LongValuesOverOdbc/JetTest.cs | 19 +++++ .../Model80_LongValuesOverOdbc/Table.cs | 15 ++++ .../Model80_LongValuesOverOdbc/Test.cs | 85 +++++++++++++++++++ 7 files changed, 181 insertions(+) create mode 100644 test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Context.cs create mode 100644 test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/JetTest.cs create mode 100644 test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Table.cs create mode 100644 test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Test.cs diff --git a/src/EFCore.Jet/Storage/Internal/JetByteArrayTypeMapping.cs b/src/EFCore.Jet/Storage/Internal/JetByteArrayTypeMapping.cs index 7c47a859..8687a87d 100644 --- a/src/EFCore.Jet/Storage/Internal/JetByteArrayTypeMapping.cs +++ b/src/EFCore.Jet/Storage/Internal/JetByteArrayTypeMapping.cs @@ -67,6 +67,14 @@ protected override void ConfigureParameter(DbParameter parameter) parameter.Size = value == null || value == DBNull.Value || length != null && length <= maxSpecificSize ? maxSpecificSize : -1; + + //The Access ODBC driver refuses a binary parameter over 510 bytes (HY104) unless it is long binary. + //OdbcType.Image = 9; + if (parameter.Size == -1) + { + var setodbctype = parameter.GetType().GetMethods().FirstOrDefault(x => x.Name == "set_OdbcType"); + setodbctype?.Invoke(parameter, [9]); + } } /// diff --git a/src/EFCore.Jet/Storage/Internal/JetJsonTypeMapping.cs b/src/EFCore.Jet/Storage/Internal/JetJsonTypeMapping.cs index ff7ac2fb..89099801 100644 --- a/src/EFCore.Jet/Storage/Internal/JetJsonTypeMapping.cs +++ b/src/EFCore.Jet/Storage/Internal/JetJsonTypeMapping.cs @@ -107,6 +107,25 @@ protected virtual string EscapeSqlLiteral(string literal) protected override string GenerateNonNullSqlLiteral(object value) => $"'{EscapeSqlLiteral(JsonSerializer.Serialize(value))}'"; + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + protected override void ConfigureParameter(DbParameter parameter) + { + base.ConfigureParameter(parameter); + + //The Access ODBC driver refuses a string parameter over 255 characters (HY104) unless it is long text. + //OdbcType.NText = 12; + if (parameter.Value is string { Length: > 255 }) + { + var setodbctype = parameter.GetType().GetMethods().FirstOrDefault(x => x.Name == "set_OdbcType"); + setodbctype?.Invoke(parameter, [12]); + } + } + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore.Jet/Storage/Internal/JetStringTypeMapping.cs b/src/EFCore.Jet/Storage/Internal/JetStringTypeMapping.cs index bb8162fb..55a35bd3 100644 --- a/src/EFCore.Jet/Storage/Internal/JetStringTypeMapping.cs +++ b/src/EFCore.Jet/Storage/Internal/JetStringTypeMapping.cs @@ -90,6 +90,14 @@ protected override void ConfigureParameter(DbParameter parameter) length != null && length <= _maxSpecificSize ? _maxSpecificSize : -1; + + //The Access ODBC driver refuses a string parameter over 255 characters (HY104) unless it is long text. + //OdbcType.NText = 12; + if (parameter.Size == -1) + { + var setodbctype = parameter.GetType().GetMethods().FirstOrDefault(x => x.Name == "set_OdbcType"); + setodbctype?.Invoke(parameter, [12]); + } } /// diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Context.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Context.cs new file mode 100644 index 00000000..6d71acb6 --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Context.cs @@ -0,0 +1,27 @@ +using System.Data.Common; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + public class Context : DbContext + { + public Context(DbConnection connection) : + base(TestBase.GetContextOptions(connection)) + { + TestBase.TryCreateTables(this); + } + + public DbSet Table { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity
( + b => + { + b.Property(x => x.Text).HasColumnType("longchar"); + b.Property(x => x.Binary).HasColumnType("longbinary"); + b.ComplexProperty(x => x.Document, d => d.ToJson()); + }); + } + } +} diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/JetTest.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/JetTest.cs new file mode 100644 index 00000000..5e52518a --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/JetTest.cs @@ -0,0 +1,19 @@ +using System.Data.Common; +using System.Data.Odbc; +using EntityFrameworkCore.Jet.Data; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + [TestClass] + public class Model80_LongValuesOverOdbc : Test + { + // ODBC explicitly: the bug is the Access ODBC driver's, so the test must not follow the default provider. + protected override DbConnection GetConnection(string storeName) + { + var connection = new JetConnection(Helpers.CreateJetDatabase(storeName), OdbcFactory.Instance); + connection.Open(); + return connection; + } + } +} diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Table.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Table.cs new file mode 100644 index 00000000..6aba3250 --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Table.cs @@ -0,0 +1,15 @@ +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + public class Table + { + public int Id { get; set; } + public string Text { get; set; } + public byte[] Binary { get; set; } + public Document Document { get; set; } + } + + public class Document + { + public string Body { get; set; } + } +} diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Test.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Test.cs new file mode 100644 index 00000000..428a89a9 --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Test.cs @@ -0,0 +1,85 @@ +using System.Data.Common; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + // The Access ODBC driver refuses a string parameter longer than 255 characters, and a binary one longer than + // 510 bytes, with HY104 "Invalid precision value" unless it is bound as a long type (GitHub issue #306). + public abstract class Test + { + // One database per test method: MSTest runs them in parallel. + protected abstract DbConnection GetConnection(string storeName); + + [TestMethod] + public void Model80_LongValuesOverOdbc_Insert() + { + using var connection = GetConnection("Model80_LongValuesOverOdbc_Insert.accdb"); + using (var context = new Context(connection)) + { + context.Table.Add( + new Table + { + Text = new string('a', 256), + Binary = Enumerable.Range(0, 511).Select(i => (byte)i).ToArray(), + Document = new Document { Body = new string('b', 300) } + }); + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var row = context.Table.Single(); + Assert.AreEqual(new string('a', 256), row.Text); + CollectionAssert.AreEqual(Enumerable.Range(0, 511).Select(i => (byte)i).ToArray(), row.Binary); + Assert.AreEqual(new string('b', 300), row.Document.Body); + } + } + + [TestMethod] + public void Model80_LongValuesOverOdbc_Update() + { + using var connection = GetConnection("Model80_LongValuesOverOdbc_Update.accdb"); + using (var context = new Context(connection)) + { + context.Table.Add(new Table { Text = "short", Binary = [1, 2, 3], Document = new Document { Body = "short" } }); + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var row = context.Table.Single(); + row.Text = new string('a', 300); + row.Binary = new byte[8001]; + row.Document = new Document { Body = new string('b', 300) }; + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var row = context.Table.Single(); + Assert.AreEqual(new string('a', 300), row.Text); + Assert.AreEqual(8001, row.Binary.Length); + Assert.AreEqual(new string('b', 300), row.Document.Body); + } + } + + [TestMethod] + public void Model80_LongValuesOverOdbc_Where() + { + using var connection = GetConnection("Model80_LongValuesOverOdbc_Where.accdb"); + using (var context = new Context(connection)) + { + context.Table.Add(new Table { Text = new string('a', 300), Document = new Document { Body = "x" } }); + context.Table.Add(new Table { Text = "short", Document = new Document { Body = "y" } }); + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var value = new string('a', 300); + Assert.AreEqual(1, context.Table.Count(x => x.Text == value)); + } + } + } +} From cb270663184b53386ac76877f8e6fac0fe12804a Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 11 Nov 2026 21:59:15 +0800 Subject: [PATCH 25/27] Fall back to a table the query reads when the database has no #Dual A query with no table of its own (a top-level Any()) reads its FROM from JetDualTable.Name, which defaulted to #Dual. Only databases the provider creates have that table, so the query failed on any database made by Access or another tool. The table is now chosen in this order: JetDualTable.CustomName, then #Dual when the open database has it, then the first table the query itself reads. The migration lock falls back to its own lock table. JetConnection and LibRedConnection report whether #Dual exists; LibRed does so only in compatible SQL mode, the only mode that reads from it. Co-Authored-By: Claude Opus 5.5 --- .../Infrastructure/JetDualTable.cs | 2 +- .../Query/Sql/Internal/JetQuerySqlGenerator.cs | 6 +++++- src/EFCore.Jet.Data/JetConnection.cs | 5 +++++ .../Migrations/Internal/JetHistoryRepository.cs | 2 +- .../Storage/Internal/JetRelationalConnection.cs | 7 +++++++ src/LibRed/LibRed.Ado/LibRedConnection.cs | 4 +++- .../Internal/LibRedRelationalConnection.cs | 17 ++++++++++++++++- 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/EFCore.Jet.Common/Infrastructure/JetDualTable.cs b/src/EFCore.Jet.Common/Infrastructure/JetDualTable.cs index 3a6d4832..654a4cfb 100644 --- a/src/EFCore.Jet.Common/Infrastructure/JetDualTable.cs +++ b/src/EFCore.Jet.Common/Infrastructure/JetDualTable.cs @@ -41,7 +41,7 @@ public static class JetDualTable /// /// The DUAL table or query the scaffolding factory last detected in the database. /// - public static string DetectedName { get; set; } = "#Dual"; + public static string DetectedName { get; set; } = ""; /// /// The name to generate into SQL: the user's when one has been set, diff --git a/src/EFCore.Jet.Common/Query/Sql/Internal/JetQuerySqlGenerator.cs b/src/EFCore.Jet.Common/Query/Sql/Internal/JetQuerySqlGenerator.cs index 8073b388..1e64a2d0 100644 --- a/src/EFCore.Jet.Common/Query/Sql/Internal/JetQuerySqlGenerator.cs +++ b/src/EFCore.Jet.Common/Query/Sql/Internal/JetQuerySqlGenerator.cs @@ -39,6 +39,7 @@ public class JetQuerySqlGenerator : QuerySqlGenerator, IJetExpressionVisitor private List _nullNumerics = []; private Stack parent = new(); private CoreTypeMapping? _boolTypeMapping; + private TableExpression? _queryTable; /// /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. @@ -208,6 +209,7 @@ protected override Expression VisitSelect(SelectExpression selectExpression) private void VisitJetTables(IReadOnlyList tables, bool addFromSql, out List colexp) { colexp = []; + _queryTable ??= tables.OfType().FirstOrDefault(); if (tables.Count == 0) { GeneratePseudoFromClause(); @@ -524,8 +526,10 @@ private static bool IsNonComposedSetOperation(SelectExpression selectExpression) protected override void GeneratePseudoFromClause() { + var dualTableName = string.IsNullOrEmpty(JetDualTable.Name) ? _queryTable?.Name : JetDualTable.Name; + Sql.AppendLine() - .Append("FROM " + "(SELECT COUNT(*) FROM `" + JetDualTable.Name + "`)"); + .Append("FROM " + "(SELECT COUNT(*) FROM `" + dualTableName + "`)"); } private void GenerateList( diff --git a/src/EFCore.Jet.Data/JetConnection.cs b/src/EFCore.Jet.Data/JetConnection.cs index 2a8736a6..a031e95a 100644 --- a/src/EFCore.Jet.Data/JetConnection.cs +++ b/src/EFCore.Jet.Data/JetConnection.cs @@ -1,6 +1,7 @@ using EntityFrameworkCore.Jet.Data.JetStoreSchemaDefinition; using Microsoft.Win32; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Data.Common; @@ -408,6 +409,10 @@ public override void Open() } } + private static readonly ConcurrentDictionary _hasDualTable = new(StringComparer.Ordinal); + + public bool HasDualTable => _hasDualTable.GetOrAdd(ActiveConnectionString!, _ => TableExists(DefaultDualTableName)); + /// /// Gets a string that represents the version of the server to which the object is connected. /// diff --git a/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs b/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs index d1dc0e47..e22f4476 100644 --- a/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs +++ b/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs @@ -305,7 +305,7 @@ private IRelationalCommand CreateLockTableCommand() private IRelationalCommand CreateInsertLockCommand(DateTimeOffset timestamp) { var timestampLiteral = Dependencies.TypeMappingSource.GetMapping(typeof(DateTimeOffset)).GenerateSqlLiteral(timestamp); - var dualTableName = JetDualTable.Name; + var dualTableName = string.IsNullOrEmpty(JetDualTable.Name) ? LockTableName : JetDualTable.Name; return Dependencies.RawSqlCommandBuilder.Build($""" INSERT INTO `{LockTableName}` (`Id`, `Timestamp`) diff --git a/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs b/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs index 10face47..0008c6a0 100644 --- a/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs +++ b/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs @@ -1,6 +1,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Data; using EntityFrameworkCore.Jet.Data; +using EntityFrameworkCore.Jet.Infrastructure; using EntityFrameworkCore.Jet.Infrastructure.Internal; namespace EntityFrameworkCore.Jet.Storage.Internal @@ -29,6 +31,11 @@ protected override DbConnection CreateDbConnection() var connection = (JetConnection)JetFactory.Instance.CreateConnection(); connection.DataAccessProviderFactory = _jetOptionsExtension.DataAccessProviderFactory!; connection.ConnectionString = ConnectionString!; + connection.StateChange += (_, e) => + { + if (e.CurrentState == ConnectionState.Open) + JetDualTable.DetectedName = connection.HasDualTable ? JetConnection.DefaultDualTableName : ""; + }; return connection; } diff --git a/src/LibRed/LibRed.Ado/LibRedConnection.cs b/src/LibRed/LibRed.Ado/LibRedConnection.cs index 3ad3d2dd..3c27123c 100644 --- a/src/LibRed/LibRed.Ado/LibRedConnection.cs +++ b/src/LibRed/LibRed.Ado/LibRedConnection.cs @@ -161,7 +161,9 @@ public static void CreateDatabase( /// the last thing tying this assembly to the Windows-only EFCore.Jet.Data, for no benefit beyond a /// five-character string. /// - internal const string DualTableName = "#Dual"; + public const string DualTableName = "#Dual"; + + public bool HasDualTable => _database?.Catalog.FindTable(DualTableName) is not null; // The DAO/ADOX creation path created this via ISchemaOperationsProvider.EnsureDualTable; native // creation must do the same or those queries fail to bind. diff --git a/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs b/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs index f6469a52..a653ce1a 100644 --- a/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs +++ b/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs @@ -1,3 +1,7 @@ +using System.Data; +using EntityFrameworkCore.Jet.Infrastructure; +using EntityFrameworkCore.LibRed.Infrastructure; +using EntityFrameworkCore.LibRed.Infrastructure.Internal; using LibRed.Data; namespace EntityFrameworkCore.LibRed.Storage.Internal; @@ -11,5 +15,16 @@ public class LibRedRelationalConnection(RelationalConnectionDependencies depende : RelationalConnection(dependencies), ILibRedRelationalConnection { protected override DbConnection CreateDbConnection() - => new LibRedConnection { ConnectionString = ConnectionString }; + { + var connection = new LibRedConnection { ConnectionString = ConnectionString }; + if (Dependencies.ContextOptions.FindExtension()?.SqlMode == LibRedSqlMode.Compatible) + { + connection.StateChange += (_, e) => + { + if (e.CurrentState == ConnectionState.Open) + JetDualTable.DetectedName = connection.HasDualTable ? LibRedConnection.DualTableName : ""; + }; + } + return connection; + } } \ No newline at end of file From ac10b20fa024317bc9c3e5b217d3a5bfa91d2a7e Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 11 Nov 2026 23:15:38 +0800 Subject: [PATCH 26/27] Allow any EF Core and .NET 11 patch release again The .NET 11 migration pinned EFCoreVersion and MSLibVersion to an exact build, so a preview or RC could not float underneath the baselines. The GA update kept the exact pin at [11.0.0], so the packages required EF Core, System.Data.Odbc and System.Data.OleDb 11.0.0 and nothing later. Both are [11.0.0,11.0.999] again, as they were for EF 10. Co-Authored-By: Claude Opus 5.5 --- Directory.Packages.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index b903c0ca..fbcb09b5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,8 +1,8 @@ true - [11.0.0] - [11.0.0] + [11.0.0,11.0.999] + [11.0.0,11.0.999] From 24a13c30c19027ec9d8adcfb5577df752a2a3b6d Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 11 Nov 2026 23:17:59 +0800 Subject: [PATCH 27/27] Require System.Data.Odbc and System.Data.OleDb 11.0.0 at run time JetFactory still accepted 9.0.0 of either, though the packages have required 11.0.0 since the move to .NET 11. Co-Authored-By: Claude Opus 5.5 --- src/EFCore.Jet.Data/JetFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EFCore.Jet.Data/JetFactory.cs b/src/EFCore.Jet.Data/JetFactory.cs index c2beb7c5..f238f93b 100644 --- a/src/EFCore.Jet.Data/JetFactory.cs +++ b/src/EFCore.Jet.Data/JetFactory.cs @@ -9,8 +9,8 @@ namespace EntityFrameworkCore.Jet.Data /// public class JetFactory : DbProviderFactory { - public static readonly Version MinimumRequiredOdbcVersion = new(9, 0, 0); - public static readonly Version MinimumRequiredOleDbVersion = new(9, 0, 0); + public static readonly Version MinimumRequiredOdbcVersion = new(11, 0, 0); + public static readonly Version MinimumRequiredOleDbVersion = new(11, 0, 0); public static readonly JetFactory Instance = new();