As database migrations and seeding data becomes more code based and more complex , you may find you have problems debugging some of this code.
For instance if you are using package manager to run the update-database command, you may get the following errors:
c# - Validation failed for one or more entities while saving changes to SQL Server Database
Debugging Package Manager Console Update-Database Seed Method
A first chance exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll
If this is the case, i found the following solution helpful....
- Open up another version of Visual Studio
- In the new instance of visual studio: open up the file for editing and insert a break point where you suspect a problem is occurring.
- Go to the Debug menu and use the attach to process method, to attach to your existing copy of Visual Studio.
- In your originalinstance of visual studio go to the package manager console and run "update-database".
- When your seed data code is run, you will now hit a break point.