You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using Microsoft.EntityFrameworkCore;
using Npgsql;
using Xunit;
namespace DateOnlyNpgsql;
public class TestEntity
{
public int Id { get; set; }
public DateOnly Date { get; set; }
public int Diff { get; set; }
}
public class MyTest
{
[Fact]
public async Task InvalidCastExample()
{
var x = new DbCtx();
await x.Database.EnsureDeletedAsync();
await x.Database.EnsureCreatedAsync();
var e = new TestEntity()
{
Id = 1,
Date = DateOnly.Parse("2023-09-26"),
Diff = 1
};
x.TestEntities.Add(e);
await x.SaveChangesAsync();
var query = x.TestEntities
.Select(x => new
{
x.Id,
NextMonth = x.Date.AddDays(x.Diff)
});
// System.InvalidCastException: Can't cast database type timestamp without time zone to DateOnly
var a1 = query.ToArray();
}
}
public class DbCtx : DbContext
{
public DbSet<TestEntity> TestEntities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseNpgsql(
new NpgsqlConnection("Host=localhost;Uid=postgres;Pwd=mysecretpassword;Database=DummyDatabase"));
}
Tested on 6.0.22 and 7.0.11
The text was updated successfully, but these errors were encountered:
roji
changed the title
InvalidCastException: Can't cast database type timestamp without time zone to DateOnly
DateOnly.AddDays, Months and Years can't be projected out
Nov 19, 2023
Here is the code to reproduce the bug:
Tested on 6.0.22 and 7.0.11
The text was updated successfully, but these errors were encountered: