Unable to Retrieve Metadata

后端 未结 6 2199
傲寒
傲寒 2020-11-29 10:01

MVC4 + Entity Framework 4.4 + MySql + POCO/Code First

I\'m setting up the above configuration .. here are my classes:

namespace BTD.         


        
6条回答
  •  心在旅途
    2020-11-29 10:49

    Using VS 2013, MySQL Connector/NET 6.9.6, Entity Framework 6, Web API 2.2 and MySQL server 5.7 I had to combine the answers to prevent the error about "Unable to retrieve metadata".

    To successfully add a controller to a .NET project that uses a MySQL connection, do the following:

    1. Temporarily add a connection string with System.Data.SqlClient as the providerName, and comment the one for MySQL. It doesn't matter whether the connection string is valid.
    2. Ensure that MySqlEFConfiguration isn't enabled in any way.
    3. Rebuild.

    About the second point, the MySQL documentation on using Connector/NET with EF6 states three possible ways to enable the MySqlEFConfiguration. Ensure that none of these are enabled while adding controllers using the VS template.

    1. Adding the DbConfigurationTypeAttribute on the context class:

    [DbConfigurationType(typeof(MySqlEFConfiguration))]

    1. Calling DbConfiguration.SetConfiguration(new MySqlEFConfiguration()) at the application startup

    2. Set the DbConfiguration type in the configuration file:

提交回复
热议问题