asp.net-mvc – Entity Framework – Compatibility with Banks

Question:

I was reading an article that demonstrates the method of using the Entity Framework to connect to a MySQL database, however, the article demonstrates very different techniques 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 MySQL license allows us to lower the cost of the application a little, I would like to know if I can migrate my applications and still use the resources of the Entity Framework, such as the aforementioned Code First.

Answer:

I would like to know 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 provides this support:

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

You must also register the provider in your root Web.config 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 that's done, just use your context normally:

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

    // Registre seus DbSets aqui
}
Scroll to Top