You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update the SQL Server LocalDB seed data step of the ASP.NET Core Razor Pages tutorial to perform a database migration of the seed data rather than initializing during startup.
Overview
The SQL database step in the Razor Pages tutorial here (md file here) includes instructions for adding seed data to grow the size of the sample set, which enables functionality in later steps (i.e. search and adding new fields). Readers are instructed to create an initializer class and then call it from Startup.cs after retrieving the db context. The initializer will skip its work if it finds any existing records in the database table, which is ensured by previous steps in the tutorial. To get around this, there are also one-off steps to delete all records in the database and restart IIS.
As a matter of best practices, adding seed data to a database could be considered a database migration. A more effective approach would be to create an EF migration step and run the migration.
This approach removes the one-off steps and, more importantly, gives readers a better model for constructing these types of database updates for their own apps.
I have the seed data migration step code, so I don't mind taking on the task of re-writing this page to reflect the code changes.
Thank you!
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 03221075-5dfa-d1b6-0552-3fe88abe1d03
Version Independent ID: b8c7d824-35ca-68fb-e3be-839ae886657c
They finished their work for data seeding with the 2.1 release. AFAIK based on our prior discussions on this subject, we'll be moving to this approach:
Migrated from #7342 - complete #8137 before this issue.
@jabberhams wrote:
Summary
Update the SQL Server LocalDB seed data step of the ASP.NET Core Razor Pages tutorial to perform a database migration of the seed data rather than initializing during startup.
Overview
The SQL database step in the Razor Pages tutorial here (md file here) includes instructions for adding seed data to grow the size of the sample set, which enables functionality in later steps (i.e. search and adding new fields). Readers are instructed to create an initializer class and then call it from
Startup.cs
after retrieving the db context. The initializer will skip its work if it finds any existing records in the database table, which is ensured by previous steps in the tutorial. To get around this, there are also one-off steps to delete all records in the database and restart IIS.As a matter of best practices, adding seed data to a database could be considered a database migration. A more effective approach would be to create an EF migration step and run the migration.
This approach removes the one-off steps and, more importantly, gives readers a better model for constructing these types of database updates for their own apps.
I have the seed data migration step code, so I don't mind taking on the task of re-writing this page to reflect the code changes.
Thank you!
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: