Unable to Retrieve Metadata in MVC4 with Entity Framework and MySql
The error "Unable to retrieve metadata for [model class]" often arises when using Entity Framework with MySql in MVC4. This issue stems from a limitation in MVC4 controller scaffolding, which does not correctly identify MySql connection strings.
To resolve this issue, follow these steps:
During Controller Scaffolding Only:
<connectionStrings> <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="System.Data.SqlClient" /> </connectionStrings>
After Scaffolding:
<connectionStrings> <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
This workaround allows MVC4 scaffolding to properly generate the necessary metadata for your model, while still allowing your application to connect to the MySql database at runtime.
The above is the detailed content of How to Fix \'Unable to retrieve metadata\' Error when using Entity Framework and MySql in MVC4?. For more information, please follow other related articles on the PHP Chinese website!