Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute for configuring composite primary keys #27571

Merged
merged 8 commits into from
Mar 14, 2022
Merged

Conversation

ajcvickers
Copy link
Member

Fixes #11003

This PR introduces a new [PrimaryKey] which follows the same pattern as [Index] in that it is applied to the entity type class and takes an ordered list of property names. It takes precedence over any [Key] attributes on properties, since these may still be needed for OData or other technologies. PrimaryKey and Keyless cannot be used on the same type.

@ajcvickers ajcvickers requested a review from a team March 4, 2022 13:19
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a first round of comments, @AndriySvyryd will probably also want to take a look.

src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated Show resolved Hide resolved
src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated Show resolved Hide resolved
src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated Show resolved Hide resolved
src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated Show resolved Hide resolved
src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs Outdated Show resolved Hide resolved
src/EFCore/Properties/CoreStrings.Designer.cs Outdated Show resolved Hide resolved
src/EFCore/Properties/CoreStrings.resx Outdated Show resolved Hide resolved
src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated Show resolved Hide resolved
@ajcvickers
Copy link
Member Author

New version up.

ajcvickers and others added 8 commits March 14, 2022 10:08
Fixes #11003

This PR introduces a new `[PrimaryKey]` which follows the same pattern as `[Index]` in that it is applied to the entity type class and takes an ordered list of property names. It takes precedence over any `[Key]` attributes on properties, since these may still be needed for OData or other technologies. `PrimaryKey` and `Keyless` cannot be used on the same type.
Co-authored-by: Shay Rojansky <roji@roji.org>
Co-authored-by: Shay Rojansky <roji@roji.org>
Co-authored-by: Shay Rojansky <roji@roji.org>
Co-authored-by: Shay Rojansky <roji@roji.org>
Co-authored-by: Shay Rojansky <roji@roji.org>
@ajcvickers ajcvickers merged commit 5ae9bb7 into main Mar 14, 2022
@ajcvickers ajcvickers deleted the CompostableKey0302 branch March 14, 2022 11:54
@paulodero
Copy link

Great feature! A much better way to define composite keys in efcore.

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.

Attribute (Data Annotations) mapping for composite primary keys
4 participants