Skip to content

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

@PragmaticIT

Description

@PragmaticIT

Description

Hi
In the Seed the database section (here) 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions