dotnet / dotnet/EntityFramework.Docs
Include example how to RETRIEVE a list of those key fields (whether 1 key or more)
- Dominant language
- Mermaid
- Stars
- 1.7k
- Forks
- 2k
- Avg merge
- 7d 23h
- Merged PRs (30d)
- 16
Description
### Type of issue
Missing information
### Description
[Enter feedback here]
The page would be much more informative if it included examples of how to retrieve a list of the properties (or just property) that are part of the primary key.
As a generalization, it seems bad practice to illustrate how to set something but not how to get it. But there are definite use cases for this on this particular page.
For example, you want to insert a new row, but you want to pre-validate that there's not going to be a primary key violation. You might retrieve a list of PK values and write code to check that your new entity won't throw this error when you try to insert. If it's a single-value key, not too hard. But if you want a general piece of code that will retrieve a primary key value from an entity regardless of the number of properties involved in the key.
Thanks!
### Page URL
https://learn.microsoft.com/en-us/ef/core/modeling/keys?tabs=data-annotations
### Content source URL
https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/modeling/keys.md
### Document Version Independent Id
f1fba5b2-eb2e-da0a-fce0-d492855c1777
### Article author
@AndriySvyryd
Contributor guide
Assessment
This issue has not been assessed yet.