Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 2, 2026

The CreateAsync_ShouldPersistLamp test failed because Entity Framework Core couldn't populate database-generated timestamps on entities using init accessors. EF Core can only set properties during object construction when using init, but ReloadAsync() operates on existing instances.

Changes

  • LampDbEntity.cs: Changed property accessors from init to set to allow post-construction mutation by EF Core
  • LampControlDbContext.cs: Added ValueGeneratedOnAdd() for CreatedAt and ValueGeneratedOnAddOrUpdate() for UpdatedAt to signal EF Core these values come from the database

This enables the repository's CreateAsync method to rely on PostgreSQL's DEFAULT CURRENT_TIMESTAMP constraints and update triggers rather than setting timestamps in application code:

var dbEntity = new LampDbEntity
{
    Id = entity.Id,
    IsOn = entity.Status,
    DeletedAt = null,
    // CreatedAt and UpdatedAt omitted - database generates them
};

this.context.Lamps.Add(dbEntity);
await this.context.SaveChangesAsync();
await this.context.Entry(dbEntity).ReloadAsync(); // Now populates timestamps

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…rated configuration

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 2, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/files-to-index5987092168840376068.list --sourceArchiveDir=/home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/src --outputDir=/home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/trap/csharp n.current/8.0.0/ .dotnet/sdk-manifests/8.0.100/microsoft.net.workload.mono.toolchain.current/8.0.0/ 93656f9bd8cfd8f3git by/c4ac5d679fec1add f9906a906e09a05a. ca599a0e5420dff8172.17.0.2 /var�� (dns block)
  • crl.comodoca.com
    • Triggering command: /home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/lamp-control-api-reference/lamp-control-api-reference/src/csharp/LampControlApi/LampControlApi.csproj --packages /home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot f75/log.json -q create runtime-runc/moby ctl io.containerd.rumkdir Release 0/ ctl (dns block)
  • ocsp.comodoca.com
    • Triggering command: /home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/lamp-control-api-reference/lamp-control-api-reference/src/csharp/LampControlApi/LampControlApi.csproj --packages /home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/lamp-control-api-reference/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot f75/log.json -q create runtime-runc/moby ctl io.containerd.rumkdir Release 0/ ctl (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Implement PostgreSQL storage with Entity Framework Core Fix EF Core timestamp population by using mutable properties and ValueGenerated configuration Jan 2, 2026
Copilot AI requested a review from davideme January 2, 2026 16:18
@davideme davideme marked this pull request as ready for review January 2, 2026 16:25
@davideme davideme merged commit 38cc65b into feature/csharp-postgresql-storage Jan 2, 2026
@davideme davideme deleted the copilot/sub-pr-250 branch January 2, 2026 16:25
davideme added a commit that referenced this pull request Jan 5, 2026
…#250)

* Implement PostgreSQL storage with Entity Framework Core for C# (#248)

* Initial plan

* Implement C# PostgreSQL storage support with Entity Framework Core

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Fix C# tests by using environment-based PostgreSQL configuration

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Add PostgreSQL implementation guide for remaining languages

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Address code review feedback: simplify repository pattern and fix paths

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Add comprehensive implementation summary and complete C# PostgreSQL support

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Remove PostgreSQL implementation documentation

Deleted POSTGRESQL_IMPLEMENTATION_GUIDE.md and POSTGRESQL_IMPLEMENTATION_SUMMARY.md, which contained implementation steps, patterns, and summary reports for PostgreSQL support across multiple language stacks.

* Add unit tests for database and repository logic

Added Microsoft.EntityFrameworkCore.InMemory as a test dependency. Introduced unit tests for LampControlDbContext, LampDbEntity, and PostgresLampRepository to verify entity behavior, soft delete logic, CRUD operations, and error handling using the in-memory database provider.

* Address PR review feedback: simplify config, clarify health checks, use DB trigger for timestamps, apply actual schema in tests

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davideme <858090+davideme@users.noreply.github.com>
Co-authored-by: Davide Mendolia <davide@gokarumi.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Replace brittle path construction with repository root detection in PostgreSQL tests (#251)

* Initial plan

* Replace brittle path construction with robust FindRepositoryRoot method

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Fix XML documentation issues in test files

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Fix EF Core timestamp population by using mutable properties and ValueGenerated configuration (#252)

* Initial plan

* Fix EF Core timestamp generation by using set accessors and ValueGenerated configuration

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Update devcontainer and test package versions

Added Docker-in-Docker feature to the devcontainer configuration. Updated Microsoft.AspNetCore.Mvc.Testing NuGet package to version 8.0.11 and refreshed transitive dependencies in the lock file for improved compatibility and security.

* Update NuGet package versions in packages.lock.json

Bump several Microsoft.AspNetCore and Microsoft.Extensions package versions to latest 8.0.x releases in packages.lock.json for LampControlApi. This ensures compatibility with recent bug fixes and improvements from upstream dependencies.

* Update dependencies and add BouncyCastle.Cryptography

Upgraded Moq, Npgsql.EntityFrameworkCore.PostgreSQL, Microsoft.EntityFrameworkCore.Design, Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore, and Microsoft.EntityFrameworkCore.InMemory to latest versions. Added BouncyCastle.Cryptography as a new package dependency.

* Move and restructure test project to separate directory

Renamed and relocated all test files from 'src/csharp/LampControlApi/Tests' to 'src/csharp/LampControlApi.Tests' for better project organization. Added a new test project file 'LampControlApi.Tests.csproj' with necessary dependencies and project references. Updated the solution file to include the new test project.

* Refactor C# CI workflow for multi-project support

Updated the GitHub Actions workflow to operate from the src/csharp directory and explicitly target both LampControlApi and LampControlApi.Tests projects for restore, build, format, test, and security scan steps. Improved dependency caching, artifact paths, and reporting to handle both main and test projects, enabling more robust CI for multi-project solutions.

* Move solution file to src/csharp directory

Renamed and relocated LampControlApi.sln to src/csharp/LampControlApi.sln. Updated project paths within the solution file to reflect the new location.

* Simplify and generalize .NET workflow commands

Refactored the GitHub Actions workflow to use more generic dotnet CLI commands, reducing repetition and improving maintainability. Updated dependency caching to include both main and test project lock files. Consolidated package listing and security scanning steps to operate on the solution as a whole rather than individual projects.

* Use locked mode for dotnet restore in CI workflow

Updated all 'dotnet restore' commands in the csharp-ci GitHub Actions workflow to use the '--locked-mode' flag. This ensures that dependency resolution strictly follows the lock file, improving build reproducibility and reliability.

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davideme <858090+davideme@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants