Skip to content

Commit 865d9c0

Browse files
Copilotwadepickett
andauthored
Add "Apply migrations" section to MVC validation tutorial (#36817)
* Initial plan * Add Apply migrations section to MVC validation tutorial for all supported versions Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> * Apply suggestion from @wadepickett * Reinsert review note for Details and Delete methods * Update validation7.md with review note Added a note about reviewing the app and improving methods. * Reinsert review note for Details and Delete methods * Update validation9.md * Add link to Part 8 tutorial on EF Core migrations * Apply suggestions from code review Add links to new field tutorial per tdykstra review Co-authored-by: Wade Pickett <wpickett@microsoft.com> * Apply suggestion from @wadepickett * Add Part 8 link to validation.md Additional resources; update EF Core migrations links in new-field tutorials Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/6b4f3ff0-45af-46b6-aafa-bde7f5bf725e Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> Co-authored-by: Wade Pickett <wpickett@microsoft.com>
1 parent 17dbfed commit 865d9c0

9 files changed

Lines changed: 177 additions & 7 deletions

File tree

aspnetcore/tutorials/first-mvc-app/new-field.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: wadepickett
55
description: Part 8 of tutorial series on ASP.NET Core MVC.
66
monikerRange: '>= aspnetcore-3.1'
77
ms.author: wpickett
8-
ms.date: 02/24/2026
8+
ms.date: 03/26/2026
99
uid: tutorials/first-mvc-app/new-field
1010
---
1111
# Part 8, add a new field to an ASP.NET Core MVC app
@@ -14,7 +14,7 @@ uid: tutorials/first-mvc-app/new-field
1414

1515
:::moniker range=">= aspnetcore-10.0"
1616

17-
In this section [Entity Framework](/ef/core/get-started/aspnetcore/new-db) Migrations is used to:
17+
In this section [Entity Framework Core migrations](/ef/core/managing-schemas/migrations/) is used to:
1818

1919
* Add a new field to the model.
2020
* Migrate the new field to the database.

aspnetcore/tutorials/first-mvc-app/new-field/includes/new-field6.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:::moniker range="= aspnetcore-6.0"
22

3-
In this section [Entity Framework](/ef/core/get-started/aspnetcore/new-db) Code First Migrations is used to:
3+
In this section [Entity Framework Core migrations](/ef/core/managing-schemas/migrations/) is used to:
44

55
* Add a new field to the model.
66
* Migrate the new field to the database.

aspnetcore/tutorials/first-mvc-app/new-field/includes/new-field7.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:::moniker range="= aspnetcore-7.0"
22

3-
In this section [Entity Framework](/ef/core/get-started/aspnetcore/new-db) Code First Migrations is used to:
3+
In this section [Entity Framework Core migrations](/ef/core/managing-schemas/migrations/) is used to:
44

55
* Add a new field to the model.
66
* Migrate the new field to the database.

aspnetcore/tutorials/first-mvc-app/new-field/includes/new-field8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:::moniker range="= aspnetcore-8.0"
22

3-
In this section [Entity Framework](/ef/core/get-started/aspnetcore/new-db) Code First Migrations is used to:
3+
In this section [Entity Framework Core migrations](/ef/core/managing-schemas/migrations/) is used to:
44

55
* Add a new field to the model.
66
* Migrate the new field to the database.

aspnetcore/tutorials/first-mvc-app/validation.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
title: Part 9, add validation to an ASP.NET Core MVC app
3+
ai-usage: ai-assisted
34
author: wadepickett
45
description: Part 9 of tutorial series on ASP.NET Core MVC.
56
monikerRange: '>= aspnetcore-3.1'
67
ms.author: wpickett
7-
ms.date: 01/22/2026
8+
ms.date: 03/26/2026
89
uid: tutorials/first-mvc-app/validation
910
---
1011

@@ -135,8 +136,42 @@ You can use the `DisplayFormat` attribute by itself, but it's generally a good i
135136
* The `DataType` attribute can enable MVC to choose the right field template to render the data (the `DisplayFormat` if used by itself uses the string template).
136137

137138

139+
## Apply migrations
140+
141+
Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.
142+
143+
# [Visual Studio](#tab/visual-studio)
144+
145+
From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.
146+
147+
In the PMC, enter the following commands:
148+
149+
```powershell
150+
Add-Migration New_DataAnnotations
151+
Update-Database
152+
```
153+
154+
# [Visual Studio Code](#tab/visual-studio-code)
155+
156+
[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]
157+
158+
Delete the Migrations folder and the database file, and then run the following .NET CLI commands:
159+
160+
```dotnetcli
161+
dotnet ef migrations add InitialCreate
162+
```
163+
164+
```dotnetcli
165+
dotnet ef database update
166+
```
167+
168+
For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).
169+
170+
---
171+
138172
## Additional resources
139173

174+
* [Part 8, Add a new field (EF Core migrations)](xref:tutorials/first-mvc-app/new-field)
140175
* [Working with Forms](xref:mvc/views/working-with-forms)
141176
* [Globalization and localization](xref:fundamentals/localization)
142177
* [Introduction to Tag Helpers](xref:mvc/views/tag-helpers/intro)

aspnetcore/tutorials/first-mvc-app/validation/includes/validation6.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,44 @@ The following code shows combining attributes on one line:
102102

103103
[!code-csharp[](~/tutorials/first-mvc-app/start-mvc/sample/MvcMovie60/Models/Movie.cs?name=AttrOneLine)]
104104

105+
## Apply migrations
106+
107+
Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.
108+
109+
# [Visual Studio](#tab/visual-studio)
110+
111+
From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.
112+
113+
In the PMC, enter the following commands:
114+
115+
```powershell
116+
Add-Migration New_DataAnnotations
117+
Update-Database
118+
```
119+
120+
# [Visual Studio Code](#tab/visual-studio-code)
121+
122+
[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]
123+
124+
Delete the Migrations folder and the database file, and then run the following .NET CLI commands:
125+
126+
```dotnetcli
127+
dotnet ef migrations add InitialCreate
128+
```
129+
130+
```dotnetcli
131+
dotnet ef database update
132+
```
133+
134+
For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).
135+
136+
---
137+
105138
In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.
106139

107140
## Additional resources
108141

142+
* [Part 8, Add a new field (EF Core migrations)](xref:tutorials/first-mvc-app/new-field)
109143
* [Working with Forms](xref:mvc/views/working-with-forms)
110144
* [Globalization and localization](xref:fundamentals/localization)
111145
* [Introduction to Tag Helpers](xref:mvc/views/tag-helpers/intro)

aspnetcore/tutorials/first-mvc-app/validation/includes/validation7.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,43 @@ The following code shows combining attributes on one line:
102102

103103
[!code-csharp[](~/tutorials/first-mvc-app/start-mvc/sample/MvcMovie70/Models/Movie.cs?name=snippet_AttrOneLine)]
104104

105+
## Apply migrations
106+
107+
Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.
108+
109+
# [Visual Studio](#tab/visual-studio)
110+
111+
From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.
112+
113+
In the PMC, enter the following commands:
114+
115+
```powershell
116+
Add-Migration New_DataAnnotations
117+
Update-Database
118+
```
119+
120+
# [Visual Studio Code](#tab/visual-studio-code)
121+
122+
[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]
123+
124+
Delete the Migrations folder and the database file, and then run the following .NET CLI commands:
125+
126+
```dotnetcli
127+
dotnet ef migrations add InitialCreate
128+
```
129+
130+
```dotnetcli
131+
dotnet ef database update
132+
```
133+
134+
For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).
135+
---
136+
105137
In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.
106138

107139
## Additional resources
108140

141+
* [Part 8, Add a new field (EF Core migrations)](xref:tutorials/first-mvc-app/new-field)
109142
* [Working with Forms](xref:mvc/views/working-with-forms)
110143
* [Globalization and localization](xref:fundamentals/localization)
111144
* [Introduction to Tag Helpers](xref:mvc/views/tag-helpers/intro)

aspnetcore/tutorials/first-mvc-app/validation/includes/validation8.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,44 @@ The following code shows combining attributes on one line:
107107

108108
[!code-csharp[](~/tutorials/first-mvc-app/start-mvc/sample/mvcmovie80/Models/Movie.cs?name=snippet_AttrOneLine)]
109109

110+
## Apply migrations
111+
112+
Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.
113+
114+
# [Visual Studio](#tab/visual-studio)
115+
116+
From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.
117+
118+
In the PMC, enter the following commands:
119+
120+
```powershell
121+
Add-Migration New_DataAnnotations
122+
Update-Database
123+
```
124+
125+
# [Visual Studio Code](#tab/visual-studio-code)
126+
127+
[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]
128+
129+
Delete the Migrations folder and the database file, and then run the following .NET CLI commands:
130+
131+
```dotnetcli
132+
dotnet ef migrations add InitialCreate
133+
```
134+
135+
```dotnetcli
136+
dotnet ef database update
137+
```
138+
139+
For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).
140+
141+
---
142+
110143
In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.
111144

112145
## Additional resources
113146

147+
* [Part 8, Add a new field (EF Core migrations)](xref:tutorials/first-mvc-app/new-field)
114148
* [Working with Forms](xref:mvc/views/working-with-forms)
115149
* [Globalization and localization](xref:fundamentals/localization)
116150
* [Introduction to Tag Helpers](xref:mvc/views/tag-helpers/intro)
@@ -120,4 +154,4 @@ In the next part of the series, we review the app and make some improvements to
120154
> [Previous](~/tutorials/first-mvc-app/new-field.md)
121155
> [Next](~/tutorials/first-mvc-app/details.md)
122156
123-
:::moniker-end
157+
:::moniker-end

aspnetcore/tutorials/first-mvc-app/validation/includes/validation9.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,44 @@ The following code shows combining attributes on one line:
107107

108108
[!code-csharp[](~/tutorials/first-mvc-app/start-mvc/sample/mvcmovie90/Models/Movie.cs?name=snippet_AttrOneLine)]
109109

110+
## Apply migrations
111+
112+
Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.
113+
114+
# [Visual Studio](#tab/visual-studio)
115+
116+
From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.
117+
118+
In the PMC, enter the following commands:
119+
120+
```powershell
121+
Add-Migration New_DataAnnotations
122+
Update-Database
123+
```
124+
125+
# [Visual Studio Code](#tab/visual-studio-code)
126+
127+
[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]
128+
129+
Delete the Migrations folder and the database file, and then run the following .NET CLI commands:
130+
131+
```dotnetcli
132+
dotnet ef migrations add InitialCreate
133+
```
134+
135+
```dotnetcli
136+
dotnet ef database update
137+
```
138+
139+
For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).
140+
141+
---
142+
110143
In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.
111144

112145
## Additional resources
113146

147+
* [Part 8, Add a new field (EF Core migrations)](xref:tutorials/first-mvc-app/new-field)
114148
* [Working with Forms](xref:mvc/views/working-with-forms)
115149
* [Globalization and localization](xref:fundamentals/localization)
116150
* [Introduction to Tag Helpers](xref:mvc/views/tag-helpers/intro)

0 commit comments

Comments
 (0)