Mvc 4 add a controller with forests, giving an error - "Failed to get metadata ..."

I get the following error when trying to add a controller with CRUD actions and EF:

Unable to retrieve metadata for LetLord.Models.Tenant. Using the same DbCompiledModel to create contexts for different types of databases is not supported. Instead, create a separate DbCompiledModel for each server you use.

Add controller dialog settings:

Template: MVC controller with read / write actions and views using EF.

Model Class: Tenant (LetLord.Models)

Data Context Class: LetLordContext (LetLord.Models)

I saw similar questions / problems and tried the suggested solutions, but I can't get it to work.

My connection string:

<connectionStrings> <add name="LetLordContext" connectionString="Data Source=|DataDirectory|LetLord.Models.LetLordContext.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings> 

In LetLordContext.cs I do not have a default constructor. In the class InitializeSimpleMembershipAttribute.cs I call

 WebSecurity.InitializeDatabaseConnection("LetLordContext", "UserProfile", "UserId", "UserName", autoCreateTables: true); 

What I tried:

  • Change the name of my provider as described in different questions.
  • I deleted the connection string and commented on it.
  • Uninstall and reinstall the Entity Framework.
  • Verify that SQL Server CE 4.0 is installed.
  • Going back to an earlier version of my subversive project.

I am still at a loss, so any help would be greatly appreciated.

+1
source share
2 answers

A workaround was found, but I still did not pay attention to what caused this error.

In the root web.config file, I changed

 <connectionStrings> <add name="LetLordContext" connectionString="Data Source=|DataDirectory|LetLord.Models.LetLordContext.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings> 

to

 <connectionStrings> <add name="DefaultConnection" connectionString="Data Source=|DataDirectory|LetLord.Models.LetLordContext.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings> 

This allows me to add views using forests and after adding, I changed the line to what it was originally. As far as I know, any new line will do.

+4
source

This decision is a bit difficult, but after trying several solutions, I had to move again. I decided to create a new model with a different name and copy the internal elements of the class to the new model. Then I selected a new model in the "Add Controller" window and scaffolding was completed.

Then I deleted the old model.

I don’t know what was broken, but the new model worked fine.

0
source

All Articles