Automatic generation of Controllers and Views with . NET Entity Framework and Mysql

Asked

Viewed 180 times

0

EDIT: I solved the problem below and others that appeared later. See my answer.

I created a Business project using the Entity Framework (EF) Code First approach. I have a database in Mysql with 8 tables and they all relate even indirectly. EF connected to the database and generated me the context classes and tables. All right so far!

Then I created a MVC project, added the reference to my Business layer and went to try to add a new controller with the views scaffolding one of my tables (the problem occurs with any table, but I will exemplify with the Client one).

Adicionar -> Novo item com scaffold -> Controlador MVC 5 com modos de exibição EF

Adicionar Controlador

And this error occurs:

Erro

One of my tables has some fields like Enum. However, I have removed any reference to the SQL server provider and I am leaving only the Mysql one. Why it still tries the Sqlserver Provider??

Web.config

<connectionStrings>
    <add name="AtividadesNovaContext" connectionString="server=****;user id=****;password=****;database=atividadesnova;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.EntityFramework" />
    <providers>
        <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.18.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </providers>
</entityFramework>

Installed software and packages

  • .NET Framework 4.7.2
  • Mysql for Visual Studio 2.0.5
  • Mysql Connector . NET 8.0.18
  • Mysql.Data.Entityframework 8.0.18
  • Entityframework 6.2.0

Does anyone have any idea what might be going on?

EDIT: I updated the version of Mysql for Visual Studio to 2.0.5 (developer version). After this the error changed (updated image). I added new system information.

1 answer

0


I was able to generate the controllers and views, but I had to solve many problems besides the ones I posted here. I’ll list the problems with the solution I found.

Object reference not set to an instance of the object

  • In addition to updating the version of Mysql for Visual Studio, also temporarily place the templates in the same interface project only to run the EF.

Unable to retrieve metadata for 'Cliente'. The store type 'type' could not be found in the SqlServer provider manifest

  • Define an object MySqlEFConfiguration to the DbConfiguration at the beginning of the application. In my case, an ASP.NET MVC app, set in subroutine Application_Start() of the archive Global.asax
    DbConfiguration.SetConfiguration(New MySqlEFConfiguration())

Unable to retrieve metadata for 'Cliente' There is no store type corresponding to the conceptual side type 'SByte' of primitive type 'SByte'

  • Type Byte instead of SByte models to map the TINYINT mysql

I also had a problem with mapping the type TIMESTAMP from Mysql to the Date of VB.NET. (I have not noted the error launched.)

  • Use type MySql.Data.Types.MySqlDateTime and note the type of column for DateTime
    Imports MySql.Data.Types
    '...
    &ltColumn(TypeName:="DateTime")>
    Public Property Horario As MySqlDateTime
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.