Skip to content

Commit

Permalink
Fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRasmussen committed Nov 9, 2021
1 parent 9c01f36 commit 9ca9e93
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime.Tests
{
public class DateTimeQueryTests : QueryTestBase
{
public DateTimeQueryTests(DatabaseTestFixture databaseTestFixture)
: base(databaseTestFixture) { }

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

Assert.Equal(
condense(@$"{RaceSelectStatement} WHERE CONVERT(date, [r].[DateTimeDate]) >= '2019-07-01T00:00:00.0000000'"),
condense(this.Db.Sql));

Assert.Equal(6, raceResults.Count);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using NodaTime;
using System;
using System.Collections.Generic;
using System.Text;

namespace SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime.Tests.Models
{
Expand All @@ -11,6 +9,8 @@ public class Race

public LocalDate Date { get; set; }

public DateTime DateTimeDate { get; set; }

public LocalDateTime ScheduledStart { get; set; }

public LocalTime ScheduledStartTime { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Race>()
.HasData(
new Race { Id = 1, Date = new LocalDate(2019, 1, 1), ScheduledStartTime = new LocalTime(8, 0, 0, 0), ScheduledDuration = DurationExtensions.FromParts(1, 0, 0, 0), ScheduledStart = new LocalDateTime(2019, 1, 1, 8, 0, 0, 0) },
new Race { Id = 2, Date = new LocalDate(2019, 2, 1), ScheduledStartTime = new LocalTime(9, 1, 1, 1), ScheduledDuration = DurationExtensions.FromParts(2, 1, 1, 1), ScheduledStart = new LocalDateTime(2019, 2, 1, 9, 1, 1, 1) },
new Race { Id = 3, Date = new LocalDate(2019, 3, 1), ScheduledStartTime = new LocalTime(10, 2, 2, 2), ScheduledDuration = DurationExtensions.FromParts(3, 2, 2, 2), ScheduledStart = new LocalDateTime(2019, 3, 1, 10, 2, 2, 2) },
new Race { Id = 4, Date = new LocalDate(2019, 4, 1), ScheduledStartTime = new LocalTime(11, 3, 3, 3), ScheduledDuration = DurationExtensions.FromParts(4, 3, 3, 3), ScheduledStart = new LocalDateTime(2019, 4, 1, 11, 3, 3, 3) },
new Race { Id = 5, Date = new LocalDate(2019, 5, 1), ScheduledStartTime = new LocalTime(12, 4, 4, 4), ScheduledDuration = DurationExtensions.FromParts(5, 4, 4, 4), ScheduledStart = new LocalDateTime(2019, 5, 1, 12, 4, 4, 4) },
new Race { Id = 6, Date = new LocalDate(2019, 6, 1), ScheduledStartTime = new LocalTime(13, 5, 5, 5), ScheduledDuration = DurationExtensions.FromParts(6, 5, 5, 5), ScheduledStart = new LocalDateTime(2019, 6, 1, 13, 5, 5, 5) },
new Race { Id = 7, Date = new LocalDate(2019, 7, 1), ScheduledStartTime = new LocalTime(14, 6, 6, 6), ScheduledDuration = DurationExtensions.FromParts(7, 6, 6, 6), ScheduledStart = new LocalDateTime(2019, 7, 1, 14, 6, 6, 6) },
new Race { Id = 8, Date = new LocalDate(2019, 8, 1), ScheduledStartTime = new LocalTime(15, 7, 7, 7), ScheduledDuration = DurationExtensions.FromParts(8, 7, 7, 7), ScheduledStart = new LocalDateTime(2019, 8, 1, 15, 7, 7, 7) },
new Race { Id = 9, Date = new LocalDate(2019, 9, 1), ScheduledStartTime = new LocalTime(16, 8, 8, 8), ScheduledDuration = DurationExtensions.FromParts(9, 8, 8, 8), ScheduledStart = new LocalDateTime(2019, 9, 1, 16, 8, 8, 8) },
new Race { Id = 10, Date = new LocalDate(2019, 10, 1), ScheduledStartTime = new LocalTime(17, 9, 9, 9), ScheduledDuration = DurationExtensions.FromParts(10, 9, 9, 9), ScheduledStart = new LocalDateTime(2019, 10, 1, 17, 9, 9, 9) },
new Race { Id = 11, Date = new LocalDate(2019, 11, 1), ScheduledStartTime = new LocalTime(18, 10, 10, 10), ScheduledDuration = DurationExtensions.FromParts(11, 10, 10, 10), ScheduledStart = new LocalDateTime(2019, 11, 1, 18, 10, 10, 10) },
new Race { Id = 12, Date = new LocalDate(2019, 12, 1), ScheduledStartTime = new LocalTime(19, 11, 11, 11), ScheduledDuration = DurationExtensions.FromParts(12, 11, 11, 11), ScheduledStart = new LocalDateTime(2019, 12, 1, 19, 11, 11, 11) }
new Race { Id = 1, Date = new LocalDate(2019, 1, 1), DateTimeDate = new DateTime(2019, 1, 1), ScheduledStartTime = new LocalTime(8, 0, 0, 0), ScheduledDuration = DurationExtensions.FromParts(1, 0, 0, 0), ScheduledStart = new LocalDateTime(2019, 1, 1, 8, 0, 0, 0) },
new Race { Id = 2, Date = new LocalDate(2019, 2, 1), DateTimeDate = new DateTime(2019, 2, 1), ScheduledStartTime = new LocalTime(9, 1, 1, 1), ScheduledDuration = DurationExtensions.FromParts(2, 1, 1, 1), ScheduledStart = new LocalDateTime(2019, 2, 1, 9, 1, 1, 1) },
new Race { Id = 3, Date = new LocalDate(2019, 3, 1), DateTimeDate = new DateTime(2019, 3, 1), ScheduledStartTime = new LocalTime(10, 2, 2, 2), ScheduledDuration = DurationExtensions.FromParts(3, 2, 2, 2), ScheduledStart = new LocalDateTime(2019, 3, 1, 10, 2, 2, 2) },
new Race { Id = 4, Date = new LocalDate(2019, 4, 1), DateTimeDate = new DateTime(2019, 4, 1), ScheduledStartTime = new LocalTime(11, 3, 3, 3), ScheduledDuration = DurationExtensions.FromParts(4, 3, 3, 3), ScheduledStart = new LocalDateTime(2019, 4, 1, 11, 3, 3, 3) },
new Race { Id = 5, Date = new LocalDate(2019, 5, 1), DateTimeDate = new DateTime(2019, 5, 1), ScheduledStartTime = new LocalTime(12, 4, 4, 4), ScheduledDuration = DurationExtensions.FromParts(5, 4, 4, 4), ScheduledStart = new LocalDateTime(2019, 5, 1, 12, 4, 4, 4) },
new Race { Id = 6, Date = new LocalDate(2019, 6, 1), DateTimeDate = new DateTime(2019, 6, 1), ScheduledStartTime = new LocalTime(13, 5, 5, 5), ScheduledDuration = DurationExtensions.FromParts(6, 5, 5, 5), ScheduledStart = new LocalDateTime(2019, 6, 1, 13, 5, 5, 5) },
new Race { Id = 7, Date = new LocalDate(2019, 7, 1), DateTimeDate = new DateTime(2019, 7, 1), ScheduledStartTime = new LocalTime(14, 6, 6, 6), ScheduledDuration = DurationExtensions.FromParts(7, 6, 6, 6), ScheduledStart = new LocalDateTime(2019, 7, 1, 14, 6, 6, 6) },
new Race { Id = 8, Date = new LocalDate(2019, 8, 1), DateTimeDate = new DateTime(2019, 8, 1), ScheduledStartTime = new LocalTime(15, 7, 7, 7), ScheduledDuration = DurationExtensions.FromParts(8, 7, 7, 7), ScheduledStart = new LocalDateTime(2019, 8, 1, 15, 7, 7, 7) },
new Race { Id = 9, Date = new LocalDate(2019, 9, 1), DateTimeDate = new DateTime(2019, 9, 1), ScheduledStartTime = new LocalTime(16, 8, 8, 8), ScheduledDuration = DurationExtensions.FromParts(9, 8, 8, 8), ScheduledStart = new LocalDateTime(2019, 9, 1, 16, 8, 8, 8) },
new Race { Id = 10, Date = new LocalDate(2019, 10, 1), DateTimeDate = new DateTime(2019, 10, 1), ScheduledStartTime = new LocalTime(17, 9, 9, 9), ScheduledDuration = DurationExtensions.FromParts(10, 9, 9, 9), ScheduledStart = new LocalDateTime(2019, 10, 1, 17, 9, 9, 9) },
new Race { Id = 11, Date = new LocalDate(2019, 11, 1), DateTimeDate = new DateTime(2019, 11, 1), ScheduledStartTime = new LocalTime(18, 10, 10, 10), ScheduledDuration = DurationExtensions.FromParts(11, 10, 10, 10), ScheduledStart = new LocalDateTime(2019, 11, 1, 18, 10, 10, 10) },
new Race { Id = 12, Date = new LocalDate(2019, 12, 1), DateTimeDate = new DateTime(2019, 12, 1), ScheduledStartTime = new LocalTime(19, 11, 11, 11), ScheduledDuration = DurationExtensions.FromParts(12, 11, 11, 11), ScheduledStart = new LocalDateTime(2019, 12, 1, 19, 11, 11, 11) }
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public QueryTestBase(DatabaseTestFixture databaseTestFixture)

protected DbFunctions Functions { get; }

protected string RaceSelectStatement => "SELECT [r].[Id], [r].[Date], [r].[ScheduledDuration], [r].[ScheduledStart], [r].[ScheduledStartTime] FROM [Race] AS [r]";
protected string RaceSelectStatement => "SELECT [r].[Id], [r].[Date], [r].[DateTimeDate], [r].[ScheduledDuration], [r].[ScheduledStart], [r].[ScheduledStartTime] FROM [Race] AS [r]";

protected string RaceResultSelectStatement => "SELECT [r].[Id], [r].[EndTime], [r].[OffsetFromWinner], [r].[StartTime], [r].[StartTimeOffset] FROM [RaceResult] AS [r]";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using NodaTime;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace Microsoft.EntityFrameworkCore.SqlServer.Query.ExpressionTranslators
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Query;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.SqlServer.Query.ExpressionTranslators
{
public class NodaTimeTypesMemberTranslatorPlugin : RelationalMemberTranslatorProvider
public class NodaTimeTypesMemberTranslatorPlugin : SqlServerMemberTranslatorProvider
{
public NodaTimeTypesMemberTranslatorPlugin([NotNull] RelationalMemberTranslatorProviderDependencies dependencies)
: base(dependencies)
public NodaTimeTypesMemberTranslatorPlugin(
[NotNull] RelationalMemberTranslatorProviderDependencies dependencies,
IRelationalTypeMappingSource typeMappingSource)
: base(dependencies, typeMappingSource)
{
var sqlExpressionFactory = dependencies.SqlExpressionFactory;

Expand Down

0 comments on commit 9ca9e93

Please sign in to comment.