wrightstork / MVC-MOVIE

ASP.NET Core MVC app Tutorial from 2019
0 stars 0 forks source link

Add validation rules to the movie model #8

Open wrightstork opened 5 years ago

wrightstork commented 5 years ago

Working on this: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/validation?view=aspnetcore-3.0

wrightstork commented 5 years ago

For consistency: add-migration after applying validation rules

It's worth mentioning that some validation rules must be applied to the DB schema for consistency by adding a new migration. e.g. add-migration AddingNewRules

Mainly, the following two attributes affect the schema: 1- [Required] will alter the relevant column and make it not null 2- [StringLength(60)] will alter the type of the column and make it nvarchar(60)

wrightstork commented 5 years ago

I used Visual Studio Tools>NuGet Packet Manager > Packet Manager Console PM>Add-Migration AddNewValidationRules (I used a different migration name than the suggestion above left in the comments)

That scaffolds a migration.

PM> Update-Database