Skip to content

Commit aba8920

Browse files
Merge pull request #53 from StevenRasmussen/fix-52
Fixes #52
2 parents b89937f + 6a7657d commit aba8920

5 files changed

Lines changed: 51 additions & 8 deletions

File tree

.github/workflows/dotnetcore.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
12-
- name: Setup .NET Core
13-
uses: actions/setup-dotnet@v1
11+
- uses: actions/checkout@v4
12+
- name: Setup .NET
13+
uses: actions/setup-dotnet@v4
1414
with:
1515
dotnet-version: 10.0.x
16-
include-prerelease: true
1716
- name: Build with dotnet
1817
run: dotnet build "./src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime.sln" --configuration Release
1918
# name: Execute Tests

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,7 @@ healthchecksdb
347347
MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350-
.ionide/
350+
.ionide/
351+
352+
# Claude Code local config
353+
.claude/

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime.Tests/DateTimeQueryTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,42 @@ public async Task DateTime_Date_Test()
2222

2323
Assert.Equal(6, raceResults.Count);
2424
}
25+
26+
[Fact]
27+
public async Task DateTime_UtcNow_Test()
28+
{
29+
var raceResults = await this.Db.Race.Select(r => new { NowUtc = DateTime.UtcNow }).ToListAsync();
30+
31+
Assert.Equal(
32+
condense(@$"SELECT GETUTCDATE() AS [NowUtc] FROM [Race] AS [r]"),
33+
condense(this.Db.Sql));
34+
35+
Assert.Equal(12, raceResults.Count);
36+
}
37+
38+
[Fact]
39+
public async Task DateTime_UtcNow_Compared_Test()
40+
{
41+
var raceResults = await this.Db.Race.Where(r => r.DateTimeDate.Date >= DateTime.UtcNow).ToListAsync();
42+
43+
Assert.Equal(
44+
condense(@$"{RaceSelectStatement} WHERE CONVERT(date, [r].[DateTimeDate]) >= GETUTCDATE()"),
45+
condense(this.Db.Sql));
46+
47+
Assert.Equal(0, raceResults.Count);
48+
}
49+
50+
[Fact]
51+
public async Task DateTime_UtcNow_And_Input_Parameter_Test()
52+
{
53+
var dt = new DateTime(2019, 7, 1);
54+
var raceResults = await this.Db.Race.Where(r => dt >= DateTime.UtcNow).ToListAsync();
55+
56+
Assert.Equal(
57+
condense(@$"{RaceSelectStatement} WHERE @dt >= GETUTCDATE()"),
58+
condense(this.Db.Sql));
59+
60+
Assert.Equal(0, raceResults.Count);
61+
}
2562
}
2663
}

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<RepositoryUrl>https://github.com/StevenRasmussen/EFCore.SqlServer.NodaTime</RepositoryUrl>
1515
<RepositoryType>git</RepositoryType>
1616
<PackageTags>Entity Framework Core;entity-framework-core;EF;Data;O/RM;EntityFrameworkCore;EFCore;Noda;NodaTime;Noda Time</PackageTags>
17-
<Version>10.0.0</Version>
17+
<Version>10.0.1</Version>
1818
<PackageReadmeFile>README.md</PackageReadmeFile>
1919
</PropertyGroup>
2020

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/Storage/SqlServerNodaTimeTypeMappingSourcePlugin.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ public RelationalTypeMapping FindMapping(in RelationalTypeMappingInfo mappingInf
6060
{
6161
if (StoreTypeMappings.TryGetValue(storeTypeName, out var mappings))
6262
{
63+
// When clrType is null, defer to EF Core's default mapping source: our store
64+
// types (datetime, datetime2, etc.) all have non-NodaTime defaults that EF
65+
// can supply. Returning a NodaTime mapping here pollutes plain DateTime
66+
// expressions like DateTime.UtcNow with InstantValueConverter.
6367
if (clrType == null)
64-
return mappings[0];
68+
return null;
6569

6670
foreach (var m in mappings)
6771
if (m.ClrType == clrType)
@@ -73,7 +77,7 @@ public RelationalTypeMapping FindMapping(in RelationalTypeMappingInfo mappingInf
7377
if (StoreTypeMappings.TryGetValue(storeTypeNameBase!, out mappings))
7478
{
7579
if (clrType == null)
76-
return mappings[0].Clone(mappingInfo);
80+
return null;
7781

7882
foreach (var m in mappings)
7983
if (m.ClrType == clrType)

0 commit comments

Comments
 (0)