我添加并设计了 ADO.NET 实体数据模型 (.edmx),并生成了相应的 DDL 脚本 (.edmx.sql)。当我使用 SQL Server 2008 时,我所要做的就是通过 Transact-SQL 编辑器工具栏连接到它并执行 SQL。然而,当我尝试此方法时,它不允许我连接到 MySQL 服务器,因为它似乎只查找 Microsoft SQL Server。我有最新版本的 Connector/Net,可以将 MySQL 数据库添加为数据连接,但无法执行我需要的脚本。将实体框架模型与我的 MySQL 服务器结合使用需要执行哪些步骤?
I've added and designed an ADO.NET Entity Data Model (.edmx) and have generated the corresponding DDL Script (.edmx.sql). When I was using SQL Server 2008, all I had to do was connect to it via the Transact-SQL Editor toolbar and execute the SQL. When I try this method, however, it doesn't let me connect to the MySQL server, as it seems to be looking only for Microsoft SQL Servers. I have the latest version of Connector/Net, and can add the MySQL database as a Data Connection, but cannot execute the script I need. What steps are needed to use an Entity Framework model with my MySQL server?
发布评论
评论(1)
我在编辑数据模型时偶然发现了这个小属性:
(此选项与 Connector/Net。)
更改为
SSDLToMySQL.tt
后,右-单击并选择像平常一样从模型生成数据库...。这将生成.edmx.sql
文件,并且应该会给出几个错误(因为 .NET 使用 SQL Server 来解析.sql
文件。)生成 DDL 脚本后,我打开 MySQL Workbench 并将脚本粘贴进去。您需要确保已经有一个适当命名的模式存在于服务器上,然后运行脚本,瞧。I stumbled across this little property while editing my Data Model:
(This option was installed along side Connector/Net.)
After changing to
SSDLToMySQL.tt
, right-click and selectGenerate Database from Model...
as you would normally. This will generate the.edmx.sql
file, and should give you several errors (as .NET uses SQL Server to parse.sql
files.) After generating the DDL script, I opened up MySQL Workbench and pasted the script in. You need to make sure that an appropriately-named schema already exists on the server, then run the script, and voila.