Unable to retrieve metadata - MVC application

前端 未结 3 906
悲&欢浪女
悲&欢浪女 2020-12-20 03:01

I was following this to create a simple MVC application. After creating the model, when I tried to add controller, I got the following error :

相关标签:
3条回答
  • 2020-12-20 03:39

    I just solved this problem. Even though I am new to MVC, I am bit embarrassed to say, I was trying a work around for another problem I was having and moved my SetInitializer into my classname : DbContext class.

    The app worked just fine and the database was created fine as I changed the models but I couldn't add new controllers or modify current controllers using the scaffolding tool.

    I began receiving errors. One of them is listed above and another is:
    Unable to retrieve meta data for 'namespace.Models.class'. A file activation error occurred. The physical file name '\name.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

    Moving the SetInitializer back into my Global.asax fixed the problem.

    0 讨论(0)
  • 2020-12-20 03:43

    I found the solution. the problem is the "|DataDirectory|". I Changed "|" to "\"

    0 讨论(0)
  • 2020-12-20 03:56

    The error message is saying invalid value for AttachDbFilename which is part of your MovieDbContext connection string.

    The connection string currently shows this AttachDbFilename=|DataDirectory|\Movies.mdf so it appears the mdf file is now missing from the App_Data folder.

    0 讨论(0)
提交回复
热议问题