Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ SqlExpression TranslateDurationTotalMember(SqlExpression instance, double diviso

return null;

// Unbounded intervals have null bounds even when the interval itself isn't null.
SqlExpression Lower()
=> _sqlExpressionFactory.Function(
"lower",
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
argumentsPropagateNullability: [false],
typeof(Interval),
_typeMappingSource.FindMapping(typeof(Instant)));

Expand All @@ -234,7 +235,7 @@ SqlExpression Upper()
"upper",
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
argumentsPropagateNullability: [false],
typeof(Interval),
_typeMappingSource.FindMapping(typeof(Instant)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,39 @@ WHERE upper(n."Interval") = TIMESTAMPTZ '2018-04-25T10:31:33.666Z'
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public async Task Interval_Start_and_End_is_null(bool async)
{
await using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
async () =>
{
await using var transaction = await context.Database.BeginTransactionAsync();

var entity = await context.NodaTimeTypes.SingleAsync();
entity.Interval = new Interval(null, null);
await context.SaveChangesAsync();
Fixture.TestSqlLoggerFactory.Clear();

var query = context.NodaTimeTypes
.Select(t => new { Start = (Instant?)t.Interval.Start, End = (Instant?)t.Interval.End })
.Where(t => t.Start == null && t.End == null);

var result = async ? await query.SingleAsync() : query.Single();
Assert.Null(result.Start);
Assert.Null(result.End);

AssertSql(
"""
SELECT lower(n."Interval")::timestamptz AS "Start", upper(n."Interval")::timestamptz AS "End"
FROM "NodaTimeTypes" AS n
WHERE lower(n."Interval") IS NULL AND upper(n."Interval") IS NULL
LIMIT 2
""");
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public async Task Interval_HasStart(bool async)
Expand Down
Loading