Skip to content

Attribute for configuring composite primary keys - #27571

Merged
ajcvickers merged 8 commits into
mainfrom
CompostableKey0302
Mar 14, 2022
Merged

Attribute for configuring composite primary keys#27571
ajcvickers merged 8 commits into
mainfrom
CompostableKey0302

Conversation

@ajcvickers

Copy link
Copy Markdown
Contributor

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

@roji roji left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated
Comment thread src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated
Comment thread src/EFCore.Abstractions/PrimaryKeyAttribute.cs
Comment thread src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated
Comment thread src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs
Comment thread src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs
Comment thread src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs Outdated
Comment thread src/EFCore/Properties/CoreStrings.Designer.cs Outdated
Comment thread src/EFCore/Properties/CoreStrings.resx Outdated
Comment thread src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated
Comment thread src/EFCore/Metadata/Builders/IConventionEntityTypeBuilder.cs Outdated
@ajcvickers
ajcvickers force-pushed the CompostableKey0302 branch from 312042f to 3cbf8db Compare March 9, 2022 12:42
@ajcvickers
ajcvickers requested review from AndriySvyryd and roji March 9, 2022 12:42
@ajcvickers

Copy link
Copy Markdown
Contributor Author

New version up.

Comment thread src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated
Comment thread src/EFCore.Abstractions/PrimaryKeyAttribute.cs Outdated
Comment thread src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs Outdated
Comment thread src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs Outdated
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
Copy Markdown

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