Closed
Description
Description
To improve API design and encapsulate internal identifiers, we'll switch from using long/incremental IDs to Guid
as the primary key (Id
) for the Player
entity. The externally visible and unique identifier will be SquadNumber
, aligning with real-world conventions (e.g., tracking numbers in logistics or jersey numbers in sports).
This change improves separation between internal persistence concerns and public API contracts. Using a Guid
makes the Id
explicitly internal, while SquadNumber
is more domain-meaningful for clients.
Suggested Approach
- Replace
long Id
withGuid Id
in thePlayer
entity, with default value set viaGuid.NewGuid()
. - Retain
SquadNumber
as a required, unique, externally meaningful identifier. - Update
OnModelCreating
:- Set
.HasKey(p => p.Id)
and.Property(p => p.Id).ValueGeneratedOnAdd()
- Add
.HasIndex(p => p.SquadNumber).IsUnique()
- Set
- Reset the database and create a new initial migration (for educational purposes).
- Seed logic should continue working, now generating players with
Guid
IDs. - Update DELETE endpoints (and others if needed) to use
SquadNumber
instead ofId
for public-facing operations.
Acceptance Criteria
Player.Id
is of typeGuid
, generated viaGuid.NewGuid()
.SquadNumber
is unique and used as the public-facing identifier (e.g., in DELETE endpoints).- Fluent configuration updated accordingly in
OnModelCreating
. - A new clean initial EF Core migration exists reflecting the new schema.
- The seeded database works as expected on app startup with the new identifier model.
- Controllers and services updated to rely on
SquadNumber
in routes and validation, where appropriate.