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
{{ message }}
Repository navigation
DateOnly.AddDays, Months and Years can't be projected out #2888
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"));
}
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[/+]on Nov 19, 2023
Activity
roji commentedon Sep 26, 2023
Thanks @pil0t, I can see this bug and will work on a fix.
akmalnodirov commentedon Nov 19, 2023
Fix DateOnly.Add{Days,Months,Years}
[-]InvalidCastException: Can't cast database type timestamp without time zone to DateOnly[/-][+]DateOnly.AddDays, Months and Years can't be projected out[/+]Fix DateOnly.Add{Days,Months,Years} (#2964)
roji commentedon Nov 19, 2023