Skip to content

Commit

Permalink
Merge pull request #36 from StevenRasmussen/localdatetime-date-support
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
StevenRasmussen authored Aug 12, 2023
2 parents 861c619 + ed71313 commit e75d674
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ await this.Db.RaceResult
```

## Version History
* 7.1.0 (August 12, 2023)
* Added support for `LocalDateTime.Date` property - [#35](/../../issues/35)
* Added support for `OffsetDateTime.Date` property
* 7.0.0 (November 9, 2022)
* Initial release supporting EF Core 7.0.0
* 7.0.0-rc.1.22426.7 (September 25, 2022)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ public async Task LocalDateTime_PlusNanoseconds()
Assert.Equal(6, raceResults.Count);
}

[Fact]
public async Task LocalDateTime_Date()
{
var raceResults = await this.Db.Race.Where(r => r.ScheduledStart.Date >= new LocalDate(2019, 7, 1)).ToListAsync();

Assert.Equal(
condense(@$"{RaceSelectStatement} WHERE CAST([r].[ScheduledStart] AS date) >= '2019-07-01'"),
condense(this.Db.Sql));

Assert.Equal(6, raceResults.Count);
}

[Fact]
public async Task LocalDateTime_DatePart_Year()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public async Task OffsetDateTime_PlusMilliseconds()
Assert.Single(raceResults);
}

[Fact]
public async Task OffsetDateTime_Date()
{
var raceResults = await this.Db.RaceResult.Where(r => r.StartTimeOffset.Date >= new LocalDate(2019, 7, 1)).ToListAsync();

Assert.Equal(
condense(@$"{RaceResultSelectStatement} WHERE CAST([r].[StartTimeOffset] AS date) >= '2019-07-01'"),
condense(this.Db.Sql));

Assert.Equal(6, raceResults.Count);
}

[Fact]
public async Task OffsetDateTime_DatePart_Year()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using NodaTime;
using System;
using System.Collections.Generic;
using System.Reflection;
Expand Down Expand Up @@ -37,6 +38,10 @@ public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type r
null,
returnType);
}
else if (member.Name == nameof(LocalDateTime.Date) && returnType == typeof(LocalDate))
{
return _sqlExpressionFactory.Convert(instance, typeof(LocalDate));
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/StevenRasmussen/EFCore.SqlServer.NodaTime</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Entity Framework Core;entity-framework-core;EF;Data;O/RM;EntityFrameworkCore;EFCore;Noda;NodaTime;Noda Time</PackageTags>
<Version>7.0.0.0</Version>
<Version>7.1.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit e75d674

Please sign in to comment.