-
Notifications
You must be signed in to change notification settings - Fork 256
Description
Any methods on LocalDate e.g. AtMidnight() fail in a where clause (but succeed in a select clause).
Full Error
The LINQ expression 'DbSet<TestEntity>()
.Where(t => t.Date.AtMidnight().Hour > 0)' could not be translated. Additional information: Translation of method 'NodaTime.LocalDate.AtMidnight' failed.
Failing test (version 9.0.4)
[Fact]
public void LocalDateTests()
{
const string connString = "Host=localhost;Database=NodaTimeTests;Username=postgres;Password=postgres";
var options = new DbContextOptionsBuilder<TestDbContext>()
.UseNpgsql(connString, b => b.UseNodaTime())
.Options;
using var context = new TestDbContext(options);
context.Database.EnsureCreated();
// Succeeds
_ = context.Set<TestEntity>()
.Select(e => e.Date.AtMidnight().Hour > 0)
.ToList();
// Fails
_ = context.Set<TestEntity>()
.Where(e => e.Date.AtMidnight().Hour > 0)
.ToList();
}
private class TestDbContext(DbContextOptions options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TestEntity>();
}
}
public class TestEntity
{
public int Id { get; init; }
public LocalDate Date { get; init; }
}