Entity Framework - Bank Compatibility

Asked

Viewed 539 times

8

I was reading a article that demonstrates the method of using the Entity Framework for connection to Mysql database, however, the article demonstrates techniques quite different from the ones I use. (MVC).

Currently my applications are based on MS SQL databases, using Code First method.

I use the following Connectionstring structure:

  <connectionStrings>
    <add name="BancoDados" connectionString="Data Source=sqlserver.hospedagemdesites.ws;Initial Catalog=database;Persist Security Info=True;User ID=login;Password=senha" providerName="System.Data.SqlClient" />
  </connectionStrings>

As the broader license of Mysql allows us to cheapen the cost of the application a little, I wonder if I can migrate my applications and still use the resources of the Entity Framework, such as the aforementioned Code First.

  • Maybe this link will help you: http://stackoverflow.com/questions/20277677/dynamic-mysql-database-connection-for-entity-framework-6

2 answers

2


I wonder if I can migrate my applications and still use the resources of the Entity Framework, such as the aforementioned Code First.

Yes, you can. The Nuget package below grants this support:

https://www.nuget.org/packages/MySQL.Data.Entities/

It is also necessary to register the preview in your file Web.config root as a standard:

<entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
    <providers>
        <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
</entityFramework>

Done this, just use your context normally:

public class MeuContext: DbContext
{
    public MeuContext() : base("BancoDados")
    {
    }

    // Registre seus DbSets aqui
}

1

Mysql is one of the banks that Entity Framework with the Data Provider offered by mysql website, works correctly. The function of these Data Provider is to provide differences imposed on databases, mainly particular functionalities

Example: Top in SQL Server, limit and offset in Mysql, then the Data Provider are responsible for these changes and the Entity Framework works transparently with these Banks.

In relation to Databases, the Entity Framework works with everyone what differs are the Data Providers that in some cases do not work, but there are some paid that are the alternatives. Making it clear that the guilt ("or unwillingness") is not of the development staff of the ORM Entity Framework and yes of companies that hold the rights of Database Management Systems not to offer the Data Providers correctly.

Just reinforcing, with Mysql you will not have problems have 3 sites so far running ASP.Net MVC with Mysql, works very well.

There is one who pays the Devart with various Data Providers.

Installation:

Download the site package: dev.mysql.com and install normally on your computer. At the time of creation the window will appear the Mysql Data Provider as example below:

inserir a descrição da imagem aqui

Now just follow the steps that it makes for you all the settings. I like to work with Database First, that is, I build the database in Mysql and then I build the entities by the tool!

  • Would you please give an example? I have found this: https://www.nuget.org/packages/MySQL.Data.Entities/ which is installable via Nuget.

  • @Rafaelbarbosa I install by what is on the site! because, it shows me a configuration window that becomes the simplest possible work!

  • @Rafaelbarbosa, I edited! I think now you can make the settings...

Browser other questions tagged

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