编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

添加Mysql Entity Framework时,表'dbname.dbname.tablename'在Visual Studio中不存在错误:Table 'dbname.dbname.tablename' doesn't exists error in Visual Studio when adding Mysql Entity Framework

dwilt mysql 2022-5-11 10:22 4人围观

腾讯云服务器
添加Mysql Entity Framework时,表'dbname.dbname.tablename'在Visual Studio中不存在错误的处理方法

我正在尝试在Visual Studio中使用实体框架添加MySQL.我正在使用MySQL Server 8.0.12和8.0.12 Connector/MySql.data.错误:MysqlException:表'dbname.dbname.tablename'不存在.通常我有表,但是dbname名称显示两次.

I am trying to add MySQL with Entity Framework in Visual Studio. I am using MySQL Server 8.0.12 and also the 8.0.12 Connector/MySql.data. error: MysqlException: Table 'dbname.dbname.tablename' doesn't exists. Normally I have table but dbname name showing twice.

我的代码非常简单,我想列出表中的所有数据:

My code's very simple, I want to list all datas in my table:

 using (sakilaEntities db = new sakilaEntities()) { var list = db.country.ToList(); } 

我遇到了错误.

更新:卸载MySQL Server 8.0.12和MySQL Connector 8.0.12,然后安装MySQL Server& Connector 8.0.19.在您的网络配置中添加以下代码.

UPDATE: Uninstall MySQL Server 8.0.12 and MySQL Connector 8.0.12 then install MySQL Server&Connector 8.0.19. Add below code in your web config.

<providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.19.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> 

问题解答

在生成的Model类中,删除数据库名称.因此它应该是[Table("Table")),而不是[Table("Database.Table")).下面的示例:

In the generated Model classes, remove the database name. So it should be [Table("Table")] and not [Table("Database.Table")]. Example below:

[Table("Owners")] public partial class Owners { public int ID { get; set; } [StringLength(100)] public string ListName { get; set; } [Column("Owner", TypeName = "text")] [StringLength(65535)] public string Owner { get; set; } [StringLength(1073741823)] public string OwnerProperties { get; set; } } 

}

这篇关于添加Mysql Entity Framework时,表'dbname.dbname.tablename'在Visual Studio中不存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^