From scratch, I made a new solution with two projects: one was MVC 3 and the other a supporting EF 4.2 project. The whole thing builds successfully. From the MVC project I open the "Add Controller" dialogue and have it generate code based on the context and model I select from the supporting EF project. The "add controller" dialogue fails with the message:
Unable to retrieve metadata for 'MyModelClass'. Configuration system failed to initialize.
I've noticed that the "add controller" dialogue is actually attempting to fetch the database connection string from its web.config file. First, this strikes me as goofy-ish, since the supporting EF project already has an app.config with the connection string. But never-minding that, the best I can figure is that the connection string in the web.config is bad somehow. This is what it looks like:
<add name="Monsters2Entities"
connectionString="
metadata=res://*/Monsters.csdl|
res://*/Monsters.ssdl|
res://*/Monsters.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=.;
initial catalog=Monsters2;
integrated security=True;
pooling=False;
multipleactiveresultsets=True;
App=EntityFramework
""
providerName="System.Data.EntityClient"
/>
The connection string doesn't actually have all the ridiculous line breaks and indentation - I'm just trying to make it easier to read. Anyway, that connection string is basically identical to the connection string used in the supporting EF project upon which it is modelled. How do I correct the situation, to make the "add controller" dialgoue happy?
I had installed EF 6 which added:
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
In my config file. I had other scaffolding issues and so decided to fall back to Ef 5. After uninstalling EF 6 and reinstalling EF 5 I deleted the from the config and then I was able to build my new controller. I discovered this by using the
PM> Update-Database –Verbose
Just copy the connection string information from your EF model project App.Config into your and watch that you do not repeat any sections (entityFramework section for example)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With