【问题标题】:VS 2019 and MySQL Entity Framework duplicate database nameVS 2019 和 MySQL Entity Framework 重复数据库名称
【发布时间】:2021-03-08 02:59:34
【问题描述】:

我将实体框架添加到我的项目中,但我调用了toList() 方法,但出现错误:

okuldbEntities ent = new okuldbEntities();

private void Form1_Load(object sender, EventArgs e)
{
    dataGridView1.DataSource = ent.ogrenciler.ToList();
}

这是错误:

这个异常最初是在这个调用栈中抛出的:[External 代码]

内部异常1:MySqlException:表 'okuldb.okuldb.ogrenciler' 不存在

okuldb 是我的数据库名称,我没有找到为什么它添加了两次。

我看了很多。我安装了 VMWare 又做了一遍,但得到了相同的结果。

我的步骤:

  1. 我下载 Visual Studio 2019 社区并安装它
  2. mysql 安装程序和我安装 mysql 服务器 8.0.22、visual studio 连接器 1.2.9 和 .net 连接器 8.0.22
  3. 我创建c#项目网络4.8
  4. 在此之后,我使用 nuget 包并安装实体框架 6.4.4 和 mysql 数据实体框架 8.0.22 和 mysql 数据 8.0.22
  5. 毕竟我可以在我的项目中添加实体。

我添加 datagridview1 并编写以下代码:

 eokulEntities ent = new eokulEntities();
        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = ent.ogrencinot.ToList();
        }

我跑了,我看到了这条消息:

此异常最初是在此调用堆栈中引发的: [外部代码]

内部异常 1: MySqlException:表“eokul.eokul.ogrencinot”不存在

我尝试太多了。我找到了另一台笔记本电脑,我将其格式化并重新安装。

又是同样的错误。

我真的能做什么?

【问题讨论】:

  • 你的数据库上下文代码是什么样的?
  • 在 app.config 我的字符串:
  • 抱歉耽搁了。我希望看到 eokulEntities 类的源代码 - 这是 DbContext 不是吗?
  • 公共部分类 eokulEntities2 : DbContext { public eokulEntities2() : base("name=eokulEntities2") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } 公共虚拟 DbSet dersler { 获取;放; } 公共虚拟 DbSet ogrencibilgi { 获取;放; } 公共虚拟 DbSet ogrencinot { 获取;放; } }
  • 没有相同的表名,因为我尝试了另一个表和数据库。结果相同。

标签: c# mysql entity-framework dbconnection


【解决方案1】:

1.关闭你的 Visual Studio 项目

2.用记事本编辑 Model1.edmx 文件/或你的项目中的名称是什么/

3.替换文件中的匹配项,从 Schema="okuldb" 到 Schema=""

4.保存Model1.edmx文件

5.打开visual studio项目

6.编译项目

7.运行应用程序

【讨论】:

  • 它的工作谢谢你,但它正常吗?我真的不明白为什么要这样做:/
  • 很好的答案,我只是想知道为什么我决定在 .net 中使用 mysql
【解决方案2】:

我遇到了同样的问题。

我找到了这篇文章

https://bugs.mysql.com/bug.php?id=88507

推荐工作设置的地方。

参见章节:[2019 年 8 月 30 日 2:26] Gerard Ang

这篇文章是关于设计师的一个问题,但它也解决了我们的问题。

再见 克劳迪奥

【讨论】:

    猜你喜欢
    • 2023-01-18
    • 1970-01-01
    • 2017-10-04
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多