Home > Database > Mysql Tutorial > body text

How to Fix \'Unable to retrieve metadata\' Error when using Entity Framework and MySql in MVC4?

Mary-Kate Olsen
Release: 2024-11-01 05:35:27
Original
425 people have browsed it

How to Fix

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:

  1. Change the connection string in web.config to use the following syntax:
<connectionStrings>
    <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="System.Data.SqlClient" />
</connectionStrings>
Copy after login
  1. Generate the scaffolding for your controller and views.

After Scaffolding:

  1. Revert the connection string back to the original MySql connection string:
<connectionStrings>
    <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!