Skip to content

Conversation

@tomilodk
Copy link

@tomilodk tomilodk commented Jan 8, 2026

Summary

This PR adds support for primary keys that implement IParsable<T>, enabling CoreAdmin to work with strongly-typed ID patterns (DDD-style value objects).

Problem: Previously, CoreAdmin only supported Guid, int, and long primary keys. When using strongly-typed IDs like:

public record ResightsCvrSyncId(Guid Value) : IdBase<ResightsCvrSyncId>, IParsable<ResightsCvrSyncId>

Edit and Delete operations would fail with:

The key value at position 0 of the call to 'DbSet<Entity>.Find' was of type 'string', 
which does not match the property type of 'ResightsCvrSyncId'.

Solution: Added a ConvertPrimaryKey helper method that:

  1. Uses fast paths for Guid, int, long, string (existing behavior)
  2. Checks for IParsable<T> interface and calls the static Parse method via reflection
  3. Falls back to TypeConverter if available

Changes

  • Added System.ComponentModel using for TypeConverter fallback
  • Introduced ConvertPrimaryKey(string id, Type clrType) static helper method
  • Refactored GetEntityFromDbSet to use the new helper
  • Refactored DeleteEntityPost to use the new helper

Testing

Tested locally with a .NET 10 project using strongly-typed IDs implementing IParsable<T>. Edit and Delete operations now work correctly.

Breaking Changes

None. This is fully backwards compatible - existing behavior for Guid/int/long is preserved.


🤖 Generated with Claude Code

This adds support for primary keys that implement IParsable<T>, enabling
CoreAdmin to work with strongly-typed ID patterns (DDD-style value objects).

Previously, CoreAdmin only supported Guid, int, and long primary keys.
Now it will also work with any type that implements IParsable<T>, such as:
- record ResightsCvrSyncId(Guid Value) : IdBase<ResightsCvrSyncId>

The conversion is done via a new ConvertPrimaryKey helper that:
1. Uses fast paths for Guid, int, long, string (existing behavior)
2. Checks for IParsable<T> and calls the static Parse method
3. Falls back to TypeConverter if available

This enables Edit/Delete operations in CoreAdmin for entities using
strongly-typed IDs that implement IParsable<T>.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

1 participant