✨Refactor BaseEntity to Support Multiple Id Types #490
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Following suggestions from several developers regarding the need to support common Entity Id types in EntityFramework, such as Guid, String, and Numeric, I've made an attempt to enhance the flexibility while ensuring simplicity.
Traditionally, I've always relied on int auto-increment types as primary keys. This is primarily due to their straightforward nature and ease of sorting. However, to cater to broader needs, this PR introduces a way to seamlessly support other types without a significant overhaul of the existing project.
Changes Made:
IEntity<T>
inheriting fromIEntity
:BaseEntity
to inherit fromIEntity<T>
, specifying the desired primary key type:To use a different type like
string
for the Id, simply modify theBaseEntity
class definition toIEntity<string>
. Remember to run theadd-migration
command afterward.Note: It's advisable not to change the primary key type mid-project development.
This description offers a clear and concise explanation of the changes you've made. Remember to adjust as needed, depending on your project's PR review process and conventions.