Entity Framework Feature Suggestions

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);

68 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Mike FlaskoMike Flasko shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Hank SchultzHank Schultz commented  ·   ·  Flag as inappropriate

        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.

      • WayneWayne commented  ·   ·  Flag as inappropriate

        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.

      Feedback and Knowledge Base