Domanda

I'm learning the way ADO.NET Models works in Entity Framework with MySQL. I Generate new test model and then select "Generate Database from model"
It produce for me new file "model_name.edms.sql" - actual MySQL script for database creation.
However to execute it I have to "Connect to Server" which by default comes as SQL Server 2012. but in my case I use MySQL and not MS SQL Server. I dont have SQL12 instance, im working with MySQL

How do I change it to connect to MySQL?

P.S. I know I can use "New Query" directly on database and copy / paste content of the file and execute. also I can use MySQL Workbench and tons of other applications, however im working in VS2013 where most of the tools already integrated, I cant believe that SQL files in VS13 can be executed only trough MS SQL12

È stato utile?

Soluzione

I've just ran into the same problem and that's how to solve it. I'm using VS 2010 Ultimate but I guess it's the same in VS 2013.

First, when you connect (and execute the sql) from the toolbar you actually request to do it on the 'Transact-SQL Editor' toolbar, which means that the toolbar handles the MS databases. That's why you ALWAYS get a connection dialog to MS databases.

If MySQL package is properly installed in VS (and apparently that's the case for you) you should:

  1. Right click any existing toolbar (or go to View->Toolbars) and select MySQL. This should add the MySql Toolbar.
  2. Click on the first button from the left (in 'MySQL Toolbar') to either connect to an existing Data Connection or create a new connection to your MySql DB. A MySql script tab will be added.
  3. Copy all the sql generated from the EDMX file to the 'MySql script tab'.
  4. Run the script from the 'MySql script tab'.

That should do it. I know there's still a little copy-paste involved but at least you don't have to leave VS.

Hope that helps

cheerio

Altri suggerimenti

First, you have to be sure that you have downloaded MySQL for Visual Studio. This is NOT Connector/Net (though you should probably have that, too).

In VS, when you open Server Explorer, you should be able to add a database. Input your server name, user name, password, and don't forget to click the Advanced button and add in your port (usually 3306). All of this information can be obtained from your MySQL Workbench. Now you should be able to deploy your EDMX to your MySQL database using the same steps you would use for SQL Server.

Full steps from Oracle can be found at http://dev.mysql.com/doc/connector-net/en/connector-net-visual-studio-making-a-connection.html.

EDIT: Once you've performed the steps above, right-click in a blank space of your EDMX and choose SSDLToMySQL.tt in the dropdown on the DDL Generation Template. SSDLToSQL[version].tt is the default choice.

If you rename the whatever.edmx.sql file to whatever.edmx.mysql it will open in the proper tool and allow you to connect to your MySQL database server and run the script.
Perhaps at some point the generator will be updated to create the EDMX file with the ".mysql" instead of the ".sql" file extension to begin with.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top