-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate TimeOnly.AddHours, AddMinutes on SQLite #30223
Comments
There is no "AddSeconds" 😄 |
@ajcvickers didn't I already do this in #30109, are you seeing issues? Here's the test for TimeOnly.AddHours. |
Looks like it works on SQL Server for normal columns, but fails with JSON columns:
And fails with SQLite:
But note that in triage the team felt that these translations were a pit-of-failure anyway. :-) using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
#nullable disable
// ReSharper disable once HeapView.ObjectAllocation.Evident
#pragma warning disable CA1050
public class School
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public DateOnly Founded { get; set; }
public List<OpeningHours> OpeningHours { get; } = new();
}
[Owned]
public class OpeningHours
{
public DayOfWeek DayOfWeek { get; set; }
public TimeOnly OpensAt { get; set; }
public TimeOnly ClosesAt { get; set; }
}
public class Program
{
public static async Task Main()
{
using (var context = new SomeDbContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
await context.SaveChangesAsync();
}
using (var context = new SomeDbContext())
{
await context.Schools
.SelectMany(e => e.OpeningHours)
.Where(e => e.DayOfWeek == DayOfWeek.Friday)
.ExecuteUpdateAsync(s => s.SetProperty(t => t.OpensAt, t => t.OpensAt.AddHours(-1)));
}
}
}
public class SomeDbContext : DbContext
{
public DbSet<School> Schools => Set<School>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlite(@"Data Source=c:\local\test.db")
//.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//modelBuilder.Entity<School>().OwnsMany(e => e.OpeningHours).ToJson();
}
} |
Right... Since JSON doesn't have actual date/time types, that may be expected - we can look into it to confirm.
Yeah - I think TimeSpan/TimeOnly translations are tracked by #18844, since they require custom functions (no built-in functions for this in SQLite). There's also #19632 and #25103 (we may want to consolidate).
Interesting :) Because of the day wraparound? If so, doesn't that work the same way both in .NET and in the database? |
I think so. But maybe we shouldn't perpetuate a bad pattern... |
OK. FWIW these translations already do exist in the PG provider (since 6.0), we can have a design discussion on them... I haven't thought about these APIs specifically, but they don't seem that bad to me... |
Duplicate of #22950 |
No description provided.
The text was updated successfully, but these errors were encountered: