mysql - EF6 for MySql InvalidOperationException

标签 mysql entity-framework-6

这似乎是一个常见错误,但我见过的修复都没有起作用。我的 PC 上有两个 VS2015 EF6“代码优先从数据库”解决方案,它们具有相同的型号和 app.config 文件。他们都访问同一个数据库。一个运行,另一个抛出此异常。

The Entity Framework provider type 'MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6' registered in the application config file for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

异常从public virtual IList<NamedDbProviderService> DbProviderServices抛出

似乎将工作解决方案从一台 PC 复制到另一台 PC 会引发此异常,就像从 Git 中检查解决方案文件一样。我唯一能想到的是 NuGet 包恢复有问题,但删除或卸载包或包配置并手动替换它们并不能修复它。

最佳答案

问题似乎是解析配置时未加载 MySql 的 EF 驱动程序。在主程序中添加以下代码即可修复此问题。

    /// <summary>
    /// Force the MySql.Data.Entity Assembly to be loaded
    /// or the app.config file will not load 
    /// No need to call this function
    /// </summary>
    public static void Fix()
    {
        var name = MySql.Data.Entity.MySqlProviderInvariantName.ProviderName;
    }

关于mysql - EF6 for MySql InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41766099/

相关文章:

sql - 如何避免 Entity Framework 6 在生成的查询中添加 ORDER BY

javascript - 使用选择框中的值从数据库中获取记录

sql - 错误 1005 (HY000) : Can't create table when using foreign keys

php - 错误日志指出我有 MySQL 连接错误,但脚本运行正常

php - 仅在Safari上的php mysqli错误

c# - LINQ to Entities无法识别: LastOrDefault [duplicate]方法

javascript - SQL 数据和 JavaScript - 最佳实践

entity-framework-6 - EntityFramework - 将 WithRequired 移植到 EF Core

c# - 将 ObjectResult<Nullable<int>> 类型转换为 int

带 EF 6 的 MySql 连接器