Add controller error unable to retrieve metadata

unable to retrieve metadata for model while adding view
there was an error running the selected code generator
entity type has no key defined
unable to find matching controller
the metadata for entityframeworkdynamicproxies is invalid
there was an error running the selected code generator visual studio 2019
mvc database connection with entity framework
there was an error running the selected code generator primary key not found

I want to add controller in my MVC 4 application in VS2012 as this image:

Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MvcDemo.Models
{
    public class MovieDB
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Director { get; set; }
        public DateTime Date { get; set; }
    }
    public class MovieDBContext : DbContext
    {
        public DbSet<MovieDB> Movies { get; set; }
    }
}

Connection strings:

<connectionStrings>

<add name="DefaultConnection" 
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcDemo-20130315191956;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcDemo-20130315191956.mdf"
providerName="System.Data.SqlClient" />

<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|\Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>

</connectionStrings>

After clicking "add", this error occurs:

unable to retrieve metadata for 'MvcDDemo.Models.MovieDB'.Using the
same DbCompiledModel to create contexts against different type of
database servers is not supported.instead,create a 
separate DbCompiledModel for each type of server being used.

Any suggestion?

In Web.config, set second providerName same as first providerName, and after creating controller, undo that!

from:here

How to resolve "Unable To retrieve metadata for MVCApplication , I cant add controller in my application. i am using Empty MVC Application, i have not choose internet application. Please help me. Thanks in  unable to retrieve metadata for 'MvcDDemo.Models.MovieDB'.Using the same DbCompiledModel to create contexts against different type of database servers is not supported.instead,create a separate DbCompiledModel for each type of server being used.

My post may help in case someone has the same problem.

I tried experimenting with EF6 and EF5 in the same project, and I noticed that the <entityFramework> tag was messed up, and got the same problem above.

Here is what I did, and it solved the problem:

  1. I removed the <entityFramework> tag from Web.config
  2. Uninstalled entity framework from my MVC app using nuget
  3. Installed entity framework to my MVC app again

After removing the <entityFramework> tag and re-installing EF5 it was fixed, and I can scaffold my controllers again.

Error when adding View : Unable to retrieve metadata for 'efEntity , My specific problem is that I am unable to generate a strongly typed views using the Controller scaffolding. The error message I receive when  Learn ASP.NET MVC 5 ( Model view controller) step by step in 2 days ( 16 hours) - Duration: 36:28. .NET Interview Preparation videos 1,228,568 views

Change providerName="System.Data.SqlServerCe.4.0 to providerName="System.Data.SqlClient to fix this error.

[SOLVED], It seems that MVC4 Controller scaffolding is not properly recognizing MySql Connection String. Change the connection string as shown below  I am sure if you landed in this page you have probably seen the same clean error: “Unable to retrieve metadata for DavidZController.” or of course XyzWhateverController. . public class DavidZ { public […]

Don't forget to clean and rebuild before you try to scaffold! That was my mistake.

Unable to retrieve metadata for xyz.model.xxx in mvc, I am receiving this error while generating view.I am using MVC controller with read/write actions and views, using EF. I am Trying to generate a list  Unable to retrieve metadata for BTD.Data.Product using the same DbCompiledModel to create context against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used.

User following for providerName = "System.Data.SqlServerCe.4.0"

<add name="MovieDBContext" 
connectionString="Data Source=|DataDirectory|\Movies.sdf"
providerName="System.Data.SqlServerCe.4.0" />

ASP.NET MVC How to fix error Unable to retrieve metadata for , “Unable to retrieve metadata for DavidZController.” or of course XyzWhateverController. . public class DavidZ { public Guid Id { get;  This is because you need to create a context object for your data that will inherit from DbContext and add any needed connection details into your web.config. Alternatively, you can create a controller as a class instead and use non-EF data access. If you want to use EF: public class StudentContext : DbContext { DbSet<student> { get; set; } }

Scaffolding error in MVC : Unable to retrieve metadata for .., when we use datafirst and add a controller then thrown error like this unable to retrieve metadata for We select the MVC 5 Controller with views, using Entity Framework option: Finally, we arrive at the Add Controller dialog where we can fill in the model class and the data context class we implemented before. Make sure to select a model and a data context class. Otherwise, the Add button of the dialog won’t be enabled and you cannot click it.

unable to retrieve metadata for mvc 4, MVC and Entity Framework : Unable to retrieve the metadata for the model Let's say you are developing an MVC application and you want to add a generated controller with the It's possible that you get this error:. When I try to create a new controller with the built in scaffolding too I get the following error: "Unable to retrieve metadata for MyThing" "Using the same DbCompiledModel to create contexts against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used.

MVC and Entity Framework : Unable to retrieve the metadata for the , I'm trying to add a controller with read/write actions and views using entity framework. I select my model class and my db context but then I get the error:- Unable to retrieve metadata for 'Ultimate_Leads.Models. Error - There was an error running the selected code generator: Try Rebuilding the project.

Comments
  • the obvious part is your context is failing. the not obvious part is why. this is usually, in descending order, 1) connection string in web.config, 2) your db 3) since you seem to be using Code First, your initialization method or migration strategy could be the problem. Please explain what you have done to intialize database, what kind of db, anything relevant...
  • ok, share your connection string
  • it's definitely a problem with connecting to db, but I don't see it. you're using compact and your connection looks solid. you're using the right context...
  • In my case I have installed EF6 on my web project and EF5 on my model project.
  • In my case, I need to change connectionString="metadata***"。