Wednesday, April 9, 2014

Map MySQL schema with Entity framework 6



Visual Studio does not support Mysql after installation by default. This default behavior prevents anyone from using a MySql schema to be mapped with the entity data Framework. Visual Studio will not even recognize Mysql Servers as a data source as seen in the picture below unless a configuration is done. First we need the MySql plugin for Visual studio and the .Net connector


Preparation

Here are links to the Mysql .net Connector and the Mysql Visual Studio Plug in. Both of these are needed to generate Entity framework with Visual Studio. Just download those files and intsall them

Installing the connector

Run the file to start the installation process and click Next.

Choose the typical and install


After the files are installed, click finish and move on to the plug in

The Plug In

Now for the plug-in the process is the same. Run the installation file downloaded earlier then click ‘Next’


Click typical and click Install when the button appears

The files will be installed and there the plugin and connector are now installed.


Configuration Steps

Add this under the provider element in App/Web.config then close the file.
invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />

Just Add the references as seen below and rebuild the solution.

Now try mapping from Mysql

Add a new item to the project

Now Select the Data category and choose the Entity Data Model. Afterwards name the data model before pressing ‘Add’

Choose the ‘Generate From Database’ option and click ‘Next’

Now Press the New Connection button if the Connection needed is still not made.

You should see the MySQL database option available. Select it and continue.

Now modify the Connection properties, make sure valid properties are entered. Make sure to test for a successful connection before pressing ‘OK’.

The connection string should be generated. Press ‘Next’

Wait for the data retrieval to complete. Select the items to be added to the solution and press ‘Finish’

Press ‘OK’ for the prompts that may appear.


There, a successful data mapping of a MySQL database in .Net using Visual Studio 2013.

No comments:

Post a Comment