Skip to content

Add Entity<TModel>(repository, string tableName) constructor overload - #25

Merged
lukaferlez merged 1 commit into
masterfrom
agent/issue-24-entity-tablename-ctor
Jul 27, 2026
Merged

Add Entity<TModel>(repository, string tableName) constructor overload#25
lukaferlez merged 1 commit into
masterfrom
agent/issue-24-entity-tablename-ctor

Conversation

@bart-bot-boy

Copy link
Copy Markdown
Collaborator

Summary

Adds a further-simplified constructor overload on Entity<TModel> (and the base Entity<TModel, TFilter, TOptions> / Entity<T, TOptions> / Entity<TModel, TUpdate, TFilter, TOptions> constructor chain) that accepts a plain string tableName, e.g.:

var entity = new Entity<Identity>(repository, "I");

This is equivalent to today's:

var entity = new Entity<Identity>(repository, new Table<Identity>("I"));

Internally the new overload just delegates to the existing (repository, Table<TModel>) constructor, constructing the Table<TModel> from the given name so callers don't need to know about Table<T> for the common case. The existing (repository, Table<TModel>) constructor is untouched and remains available for advanced cases (custom schema, quoting, reusing an existing Table<T>, etc.).

Docs (docs/USAGE.md) were updated to show the simplest string-based form first, noting the Table<T> overload as the more advanced option, per the reasoning from the linked review discussion.

Changes

  • src/Simpleverse.Repository.Db/Entity/Entity.cs: added Entity(DbRepository repository, string tableName) overloads on Entity<TModel, TUpdate, TFilter, TOptions>, Entity<TModel, TFilter, TOptions>, Entity<T, TOptions>, and Entity<T>, each delegating to the existing Table<TModel>-based constructor.
  • src/Simpleverse.Repository.Db.Test/SqlServer/Entity/EntityTest.cs: added a new IdentityEntityByTableName test helper class built with the new string-based constructor, plus a test (Constructor_WhenGivenTableNameString_CreatesEquivalentTableToTableConstructorOverload) asserting it produces an equivalent Table<T>/table name to the existing Table<T>-based constructor.
  • docs/USAGE.md: reordered the "Defining an Entity" quick-start section to lead with the new string-based constructor, with the Table<T> overload described afterwards as the more advanced form.

Test plan

  • dotnet build src/Simpleverse.Repository.Db/Simpleverse.Repository.Db.csproj – succeeds, 0 warnings/errors.
  • dotnet build src/Simpleverse.Repository.Db.Test/Simpleverse.Repository.Db.Test.csproj – succeeds (only pre-existing xUnit analyzer warnings, unrelated to this change).
  • Could not execute the new/existing SQL Server-backed test suite in this sandbox (no SQL Server instance available, and this project targets net6.0 test host while only .NET 8 SDK/runtime could be installed here due to environment constraints). The new test compiles cleanly against the same DatabaseTestFixture/SqlRepository pattern used by all other tests in EntityTest.cs, and only exercises the pure C# constructor delegation (no actual DB round-trip), so it should behave identically to the other entity-construction tests in this file once run against a real SQL Server, as CI presumably does.

Risks / things to double check

  • I did not modify ProjectedEntity<...> constructors — they take an IEntity<...> instance rather than a Table<T>/table name, so the same simplification doesn't apply there. Worth confirming that's the intended scope per the issue.
  • Please verify the new overloads don't introduce ambiguity with any existing implicit conversions from string to Table<T> elsewhere in the codebase (none found in review, but worth a second look).
  • The new test only asserts TableName equivalence (via a small public TableName property added to the two test helper entity classes) since running the DB-backed test suite wasn't possible in this sandbox; a maintainer with access to CI/a SQL Server should confirm the new test passes end-to-end.

Closes #24

@lukaferlez
lukaferlez merged commit 395a95f into master Jul 27, 2026
1 check passed
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.

Simplify Entity invocation: support Entity<T>(repository, tableName) without requiring subclassing/filter args

2 participants