Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
24 changes: 13 additions & 11 deletions src/csharp/LampControlApi/Infrastructure/Database/LampDbEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@ namespace LampControlApi.Infrastructure.Database
{
/// <summary>
/// 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.
/// </summary>
public sealed record LampDbEntity
{
/// <summary>
/// Gets or initializes the unique identifier for the lamp.
/// Gets or sets the unique identifier for the lamp.
/// </summary>
public Guid Id { get; init; }
public Guid Id { get; set; }

/// <summary>
/// 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).
/// </summary>
public bool IsOn { get; init; }
public bool IsOn { get; set; }

/// <summary>
/// Gets or initializes the timestamp when the lamp was created.
/// Gets or sets the timestamp when the lamp was created.
/// Database-generated on insert.
/// </summary>
public DateTimeOffset CreatedAt { get; init; }
public DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// 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.
/// </summary>
public DateTimeOffset UpdatedAt { get; init; }
public DateTimeOffset UpdatedAt { get; set; }

/// <summary>
/// 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.
/// </summary>
public DateTimeOffset? DeletedAt { get; init; }
public DateTimeOffset? DeletedAt { get; set; }
}
}