VS 2019 and MySQL Entity Framework duplicate database name

吃可爱长大的小学妹 提交于 2021-01-05 08:55:52

问题


I added Entity Framework to my project but I call the toList() method and I'm getting an error:

okuldbEntities ent = new okuldbEntities();

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

and this is the error:

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: MySqlException: Table 'okuldb.okuldb.ogrenciler' doesn't exist

okuldb is my database name and I didn't find why it added it twice.

I looked a lot. I installed VMWare did it all again, but got the same result.

my steps:

  1. i download visual studio 2019 community and install it
  2. mysql installer and i install mysql server 8.0.22, visual studio connector 1.2.9 and .net connector 8.0.22
  3. i create c# project netframework 4.8
  4. after this i go nuget package and i install entity framework 6.4.4 and mysql data entityframework 8.0.22 and mysql data 8.0.22
  5. after all this i can add entity my project.

i add datagridview1 and i write this code:

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

and i runnig and i see this message:

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: MySqlException: Table 'eokul.eokul.ogrencinot' doesn't exist

i try too much way. i found another laptop i format it and i install again all this.

and again same error.

really what can i do?


回答1:


Use entity data code fist model instead of designer model. Change the attribute of your ogrenciler.cs model class to get rid of the database name prefix (i.e. okuldb.ogrenciler --> ogrenciler)

[Table("ogrenciler")]
public partial class ogrenciler
{
.
.
.
}



回答2:


I had the same problem.

I found this post

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

where a working setup is recommended.

See the section: [30 Aug 2019 2:26] Gerard Ang

The post is about a problem with designer, but it solved ours too.

bye Claudio



来源:https://stackoverflow.com/questions/65001562/vs-2019-and-mysql-entity-framework-duplicate-database-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!