Entity Framework - Bank Compatibility

8

I was reading a article > which demonstrates the method of using the Entity Framework to connect to MySQL database, however, the article demonstrates techniques very 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 larger MySQL license allows us to make the cost of the application a bit cheaper, I'd like to know if I can migrate my applications and still use Entity Framework features such as Code First.

    
asked by anonymous 13.08.2014 / 15:05

2 answers

2

I would like to know if I can migrate my applications and still use Entity Framework features such as Code First.

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

  

link

You must also register the provider in your Web.config root file as the default:

<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>

Once you've done this, just use your context normally:

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

    // Registre seus DbSets aqui
}
    
13.08.2014 / 19:54
1

MySQL is one of the banks that the Entity Framework with Data Provider provided by the MySQL site , works correctly. The function of these Data Provider is to provide differences imposed on databases, particularly particular features

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

Regarding Databases, the Entity Framework works with all that differs from the Entity Framework .aspx "> Data Providers which in some cases do not work, but there are some paid which are the alternatives. Making it clear that the fault (or "unwillingness") is not of the ORM Entity Framework development staff, but of the companies that have the rights of the Database Management Systems not to offer the Data Providers correctly.

Just reinforcing, with MySQL you will not have problems I have 3 websites so far running ASP.Net MVC with MySQL, it works very well.

There is one that has paid Devart with multiple Data Providers.

Installation:

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

Now just follow the steps that it does for you all the settings. I like working with Database First, that is, I build the database in MySQL and then I generate the entities by the tool!

    
13.08.2014 / 15:19