Posted in MVC

Working with MySQL – EF5 – MVC5 Alltogether

For MySQL part;

Never install the MySQL from Web Platform Installer.Get to MySQL’s website and download MySQL Installer.

This installer package installs everything you need about database-end including;

MySQL Connector
MySQL for Visual Studio
MySQL 5.5 Database

For EF5 part;

Install EF5 via Nuget like this;

Install-Package EntityFramework -version 5.0.0

This will install EF5 which works great with MySQL Connector.

For MVC5 Part;

Download MVC5 package from Microsoft download page if you haven’t already.

Add reference to EF5 libraries:
MySQL.Data.Entity (4.5 version) –> This is for EF5

“MySQL.Data.Entity for EF6”  libraries are for Entity Framework 6.But be cautious; this library may not be compatible with the connector you’re using.They need to upgrade MySQL Connector according to EF6 since there are lots of changes.

Web.config settings:

<entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF5"></defaultConnectionFactory>
  </entityFramework>
  <connectionStrings>
    <add name="YourEntities" connectionString="metadata=res://*/Models.YourModel.csdl|res://*/Models.YourModel.ssdl|res://*/Models.YourModel.msl;provider=MySql.Data.MySqlClient;provider connection string= server=localhost;user id=root;password=yourpass;database=yourdb " providerName="System.Data.EntityClient" />
  </connectionStrings>

If you’re using EF6,downgrade it to EF5.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s