我正在尝试首先获取代码以使用现有的MySQL数据库的实体框架。我从NuGet获得了Entity Framework v6.2.0和MySQL.Data.Entity v6.9.11。我确实尝试了MySQL.Data.Entity v6.10.7,但是在被与此问题相同的继承安全规则问题阻止后,恢复为6.9.11 。该配置包含以下内容(出于明显的原因删除了用户名和密码): <connectionStrings> <add name="MySql" providerName="MySql.Data.MySqlClient" connectionString="SERVER=sql-dev;Database=pen;UID=****;PWD=****;Allow User Variables=True;" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> <system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient" /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data> 通过恢复到v6.9.11,我可以查询DbSet并查看它在调试器中生成的SQL。我可以连接,并且它识别出架构是正确的,但是当我尝试执行简单的测试查询时,它会失败。 Assert.IsTrue(context.BinLocs.Count() > 0);使用调试器,我发现它失败了,因为它生成的查询使用针对SQL Server优化的语法,而该语法不适用于MySQL。实体框架生成的SQL是:SELECT [Extent1].[TID] AS [TID], [Extent1].[zone] AS [zone], [Extent1].[ProdCode] AS [ProdCode], [Extent1].[chute] AS [chute]FROM [dbo].[tbl_s_products_binlocs] AS [Extent1];不幸的是,数据库已被设置为使用`作为引号标识符,并且没有dbo模式。知道了这一点,我可以通过手动更改SQL以考虑到这一点,轻松地使此SQL运行:当我对数据库运行此SQL时,我得到了预期的结果。我无法更改数据库期望引用标识符的方式,因为已经有旧程序必须保持运行并采用此语法。因此,我需要获得实体框架来生成将与现有数据库一起使用的SQL。如何获取Entity Framework来生成带有MySQL期望的带引号的带引号的标识符的SQL?
1 回答
没有找到匹配的内容?试试慕课网站内搜索吧
- 1 回答
- 0 关注
- 191 浏览
添加回答
举报
0/150
提交
取消