MySQL 8.0.22 + EntityFramework - Table doesn't exist (database/schema twice)

0

I'm using EntityFramework for my ASP.Net website and used MsSQL before which worked fine. Now I'm trying to migrate from MsSQL to MySQL (database got migrated from MySQL to MsSQL using the Migration Wizard of MySQL Workbench 8.0.22). This is my setup:

  • Visual Studio 2019 Community Edition 16.6.1
  • Visual Studio Extension: MySQL for Visual Studio 8.0.22
  • MySQL Server 8.0.22
  • Connector/NET 8.0.22
  • Connector/ODBC 8.0.22
  • NuGet: EntityFramework 6.4.4
  • NuGet: MySql.Data 8.0.22
  • NuGet: MySql.Data.EntityFramework 8.0.22

I'm able to create the entities with EntityFrameWork from my MySQL database/schema "test". But as soon as I try to work with the entities, I get the following error:

Table 'test.test.tbl_groupspermissions' doesn't exist

I guess the problem is, that it tries to access the table "tbl_groupspermissions" with the database/schema name twice in it (test.test).

I've already checked if the name of the table is correct.

My web.config:

    <entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </providers>
</entityFramework>
<connectionStrings>
  <add name="testConnectionString" connectionString="server=localhost;port=3306;database=test;user id=root;password=******;" providerName="MySql.Data.MySqlClient" />
  <add name="testMySQLEntities" connectionString="metadata=res://*/Entities.MySQLModel.csdl|res://*/Entities.MySQLModel.ssdl|res://*/Entities.MySQLModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;port=3306;user id=root;password=******;database=test;persistsecurityinfo=True&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

The error appears on this part (testEntities.tbl_groupsstatus.Where):

    public bool hasGuestStatus(int statusId)
{
    List<tbl_groupsstatus> statis = testEntities.tbl_groupsstatus.Where(p => p.groupId == (int)ProtectedGroups.Gast).ToList();
    bool hasStatus = false;
    foreach (tbl_groupsstatus status in statis)
    {
        if (status.statusId == statusId) { hasStatus = true; }
    }
    return hasStatus;
}

The stacktrace tells me, that its using the correct driver:

    [MySqlException (0x80004005): Table 'test.test.tbl_groupspermissions' doesn't exist]
   MySql.Data.MySqlClient.MySqlStream.ReadPacket() +309
   MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) +67
   MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) +17
   MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +110
   MySql.Data.MySqlClient.MySqlDataReader.NextResult() +931
   MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +1636
   MySql.Data.EntityFramework.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +33

I've seen related problems with version 8.0.22 here, but without any satisfying solution for me:

Table 'dbname.dbname.tablename' doesn't exists error in Visual Studio when adding Mysql Entity Framework

VS 2019 and MySQL Entity Framework duplicate database name

Schema/DB Name added 2 times in EF for MYSQL DB

Entity framework migration "Table does not exist"

Thanks for any help.

UPDATE As Bradley Grainger mentioned, its propably a bug of the component MySql.Data.EntityFramework 8.0.22. Downgrade to MySql.Data.EntityFramework 8.0.21 solved the problem for me.

c#
mysql
entity-framework
asked on Stack Overflow Dec 4, 2020 by Deadman • edited Dec 6, 2020 by Deadman

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0