Skip to content

Instantly share code, notes, and snippets.

@schmitch
Created March 30, 2023 20:19
Show Gist options
  • Save schmitch/6653bc7d74bdd970e922a9bdc755474d to your computer and use it in GitHub Desktop.
Save schmitch/6653bc7d74bdd970e922a9bdc755474d to your computer and use it in GitHub Desktop.
reproducer
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using NodaTime;
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
await using ApplicationDbContext db = new();
await db.Database.EnsureDeletedAsync();
await db.Database.EnsureCreatedAsync();
var today = new LocalDate(2023, 3, 30);
await db.WorkflowListViewWithPrices.Where(d => d.WorkflowDateCreated.Date >= today).CountAsync();
[Table("workflow_list_with_prices")]
public class WorkflowListElementWithPrice
{
[Key]
[Column("workflow_id")]
public long WorkflowId { get; set; }
[Required]
[Column("workflow_date_created")]
public ZonedDateTime WorkflowDateCreated { get; set; }
}
public class ApplicationDbContext : DbContext
{
public DbSet<WorkflowListElementWithPrice> WorkflowListViewWithPrices { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseNpgsql(
"Host=localhost;Username=postgres;Password=postgres;Database=temp;",
o => o.UseNodaTime());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment