I'm at a loss for this:
I've defined my classes for a entity framework (4.1.3) code first approach. Everything was fine (I was creating the tables etc.) until I started to Seed.
Now when I do the
Add-Migration "remigrate" ; Update-Database;
I get an error on the package console "Validation failed for one or more entities. See 'EntityValidationErrors' property for more details."
I have a breakpoint in my Seed() method but because I'm running this on the console when the project is not running, I'm clueless as to how to get to the details (PS – I've seen the thread Validation failed for one or more entities while saving changes to SQL Server Database using Entity Framework which shows how I can see the property.)
I know that my Seed() method has a problem because if I put a return right after the method call, the error goes away. So how do I set my breakpoint so I can see what the validation error is? Kinda lost. Or is there some other way to trace it in the nuget console??
Best Answer
I got annoyed by this recently too. I fixed it by putting a wrapper function in the Configuration class in the Seed method, and replaced calls to
SaveChanges
with calls to my function instead. This function would simply enumerate the errors within theEntityValidationErrors
collection, and rethrow an exception where the Exception message lists the individual problems. This makes the output show up in the NuGet package manager console.Code follows:
Just replace calls to
context.SaveChanges()
withSaveChanges(context)
in your seed method.