EF 4 Code First: Model compatibility cannot be checked because the EdmMetadata type was not included in the model

前端 未结 3 1969
刺人心
刺人心 2020-12-11 01:49

I am trying to use EF 4 Code First pattern. My initialization code is as follows:

Create Model Builder:

private static DbModelBuilder CreateModelBuil         


        
3条回答
  •  无人及你
    2020-12-11 02:21

    If you are getting this error in VS 2012 and are running in debug mode using IIS Express, try switching to Visual Studio Development Server.

    I was getting the same error, in a code-first asp.net mvc 4 application, using Visual Studio 2012 on Windows 7 machine, hitting SQL Server LocalDb (the server, no *.mdf), running on my local host in debug mode.

    My initializer is marked with the DropCreateDatabaseIfModelChanges attribute, and I am calling Database.Initialize in Global.ascx.cs Application_Start. If the database is being dropped and recreated how in the heck could it complain about a missing migration table? This was especially aggrating because I'd set up another web application using the same approach and it worked flawlessly.

    Even manually dropping the database before running the app did not fix the problem.

    Comparing the "good" app to the "bad" app, the only difference was the choice of web servers. The "good" app used Visual Studio Development Server; the "bad" used IIS Express.

    I switched the "bad" app to Visual Studio Development Server and the error disappeared!

    I don't have time to dig into the "why" right now, but apparently something incorrect is being cached by IIS Express.

提交回复
热议问题