问题
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:
- i download visual studio 2019 community and install it
- mysql installer and i install mysql server 8.0.22, visual studio connector 1.2.9 and .net connector 8.0.22
- i create c# project netframework 4.8
- 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
- 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