To add a MySQL MVC Item to an existing MVC project, first add a MySQL Entity Framework model. Skip this step if you have already done this.
Configure the project to use MySQL with an Entity Framework. There are two ways to do this:
Manually add the references needed (EntityFramework, MySql.Data &MySql.Data.Entity), and add the required configuration to the
Or (preferred), take advantage of the MySQL Website Configuration tool, which allows either Entity Framework 5 or 6 with MySQL. For additional information about this tool, see Section 6.6, “MySQL Website Configuration Tool”.
Once you have configured the project to use MySQL with Entity Framework, proceed to create the model using the standard ADO.NET Entity Data Model wizard. For MySQL MVC Item Templates, you need to add the model under the "Models" folder, as illustrated below:
After selecting the MySQL connection, you need to select the database objects to include in the model.
The Pluralize or singularize generated object names option must remain unchecked, otherwise the MySQL MVC Item Template will not function properly.
Clickto generate the model, as demonstrated below:
Now, generate a new MySQL MVC Item. Right-click on the project, and selectfrom the contextual menu.
This launches the Add New Item wizard. The MySQL menu offers two options: MySQL New MVC Item and MySQL New Windows Form. Select MySQL New MVC Item, and then click .
This opens the MVC Item Template dialog. Now select the MySQL model and entity that you want to use to create the MVC item. The model dropdown list is populated based on all the MySQL Entity Framework models available in the project, entities dropdown list is populated with entities available for the selected model.
After selecting the model and entity to create the item, click entity data., and a new controller and view matching the selected entity will be added to the project. These contain the necessary back end code to render the
You can now execute the application. In our example we used the Sakila database and generated an Actor controller: