dotnet / dotnet/AspNetCore.Docs

Please consider replacing hardcoded student IDs in the Seed the Database section with live values

Open
#34,350 1 comment 0 reactions 0 assignees View on GitHub
:watch: Not Triaged aspnet-core/svc data-access/subsvc Source - Docs.ms
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 2h
Merged PRs (30d)
109

Description

### Description

Hi
In the _Seed the database_ section ([here](https://learn.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-9.0&tabs=visual-studio#seed-the-database)) new Enrollment entities are created using hardcoded (assumed) StudentID like in the following line:
`new Enrollment{StudentID=1,CourseID=1050,Grade=Grade.A},`

instead, the live ID can be used by just refering to the student entity by refering to its index in the array defined before:
`new Enrollment{StudentID=students[1].ID,CourseID=1050,Grade=Grade.A}`

This method makes the solution more futureproof and opens it to a new experiments like using GUIDs instead of autogenerated IDs etc.

### Page URL

https://learn.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-9.0&tabs=visual-studio

### Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-rp/intro.md

### Document ID

fa488196-1f98-08ea-adcc-17d9dac86727

### Article author

@tdykstra

[Related Issues](https://github.com/dotnet/AspNetCore.Docs/issues?q=is%3Aissue+is%3Aopen+fa488196-1f98-08ea-adcc-17d9dac86727)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.