API for checking database schema correctness
I would like some API for checking if database schema is correct for edmx storage model.
It could be something like
List<string> errors = new List<string>();
bool isCorrect = context.ValidateDbSchema(errors);
Hank Schultz commented
On program launch, I iterate across each DbSet and just call FirstOrDefault() on it. If there's anything wrong, that will throw an exception. This approach ensures the exceptions get thrown at program launch rather than than at runtime, the first time the specific table is accessed.
Though I agree. An API for this would be better, and I'd hope it would be faster than my approach, which adds up quickly.
I believe this is vital for enterprise systems especially those with WCF services. I would like to see it for code-first though.
It would be great to have this check run on startup of the service and effectively put it in a faulted state, dumping the errors to a specified location. It could also be exposed as an admin function of the service that developers could query to check the schema health, with info on how to fix the problems.