From db3ee27b78fb77460ecf1181c327af2decff0710 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 2 Jan 2026 16:08:51 +0000 Subject: [PATCH 1/2] Initial plan From 5f9718b9045710cf9bf727af8ae26f761ec3005e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 2 Jan 2026 16:14:18 +0000 Subject: [PATCH 2/2] Fix EF Core timestamp generation by using set accessors and ValueGenerated configuration Co-authored-by: davideme <858090+davideme@users.noreply.github.com> --- .../Database/LampControlDbContext.cs | 6 +++-- .../Infrastructure/Database/LampDbEntity.cs | 24 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/csharp/LampControlApi/Infrastructure/Database/LampControlDbContext.cs b/src/csharp/LampControlApi/Infrastructure/Database/LampControlDbContext.cs index 9b06f3e2..cb32fbe0 100644 --- a/src/csharp/LampControlApi/Infrastructure/Database/LampControlDbContext.cs +++ b/src/csharp/LampControlApi/Infrastructure/Database/LampControlDbContext.cs @@ -49,11 +49,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.CreatedAt) .HasColumnName("created_at") - .IsRequired(); + .IsRequired() + .ValueGeneratedOnAdd(); entity.Property(e => e.UpdatedAt) .HasColumnName("updated_at") - .IsRequired(); + .IsRequired() + .ValueGeneratedOnAddOrUpdate(); entity.Property(e => e.DeletedAt) .HasColumnName("deleted_at"); diff --git a/src/csharp/LampControlApi/Infrastructure/Database/LampDbEntity.cs b/src/csharp/LampControlApi/Infrastructure/Database/LampDbEntity.cs index 1b170178..9eb2eb5d 100644 --- a/src/csharp/LampControlApi/Infrastructure/Database/LampDbEntity.cs +++ b/src/csharp/LampControlApi/Infrastructure/Database/LampDbEntity.cs @@ -4,33 +4,35 @@ namespace LampControlApi.Infrastructure.Database { /// /// Database entity for the lamp table. - /// Uses init setters for EF Core compatibility while maintaining immutability after construction. + /// Uses set accessors for EF Core compatibility to allow database-generated values. /// public sealed record LampDbEntity { /// - /// Gets or initializes the unique identifier for the lamp. + /// Gets or sets the unique identifier for the lamp. /// - public Guid Id { get; init; } + public Guid Id { get; set; } /// - /// Gets a value indicating whether gets or initializes a value indicating whether the lamp is turned on (true) or off (false). + /// Gets or sets a value indicating whether the lamp is turned on (true) or off (false). /// - public bool IsOn { get; init; } + public bool IsOn { get; set; } /// - /// Gets or initializes the timestamp when the lamp was created. + /// Gets or sets the timestamp when the lamp was created. + /// Database-generated on insert. /// - public DateTimeOffset CreatedAt { get; init; } + public DateTimeOffset CreatedAt { get; set; } /// - /// Gets or initializes the timestamp when the lamp was last updated. + /// Gets or sets the timestamp when the lamp was last updated. + /// Database-generated on insert and update via trigger. /// - public DateTimeOffset UpdatedAt { get; init; } + public DateTimeOffset UpdatedAt { get; set; } /// - /// Gets or initializes the timestamp when the lamp was soft deleted, or null if active. + /// Gets or sets the timestamp when the lamp was soft deleted, or null if active. /// - public DateTimeOffset? DeletedAt { get; init; } + public DateTimeOffset? DeletedAt { get; set; } } }