Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LocalDateTime.Date and OffsetDateTime.Date #36

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading