MySQL 不支持 OUTER APPLY
我正在使用带有 MySQL 的实体框架。以下查询结果出现错误:
var foobar = ctx.ArticleBase.OfType<ActicleSpecial>().Include("CreatedBy.Image.Location").ToList();
错误:“MySQL 不支持 OUTER APPLY” 我还在一个稍有不同的查询中得到“MySQL 不支持 CROSS APPLY”。
除了 Image 实体具有名为 Location 关系的 Location 实体(一对多关系)之外,UserBase 具有 Image 关系而不是 UserSpecial。
为什么我会收到此错误?如何避免这个错误呢?是否可以?
I am using Entity Framework with MySQL. The following query results an error:
var foobar = ctx.ArticleBase.OfType<ActicleSpecial>().Include("CreatedBy.Image.Location").ToList();
Error: "OUTER APPLY is not supported by MySQL" I also get the "CROSS APPLY is not supported by MySQL" on a little different query.
I have the following datamodel:
Except the Image entity have Location entity (one to many relation) named Location relation and UserBase have Image relation instead of UserSpecial.
Why do I get this error? How to avoid this error? Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果此错误来自 MySQL,则发生了以下两种情况之一:
如果此错误来自您的 MySQL EF 提供程序,则发生了以下两种情况之一:
SQL 由提供者生成。您可以通过 EDMX 中的ProviderManifestToken 属性来配置特定于服务器版本的 SQL 生成。这是您告诉提供商不要使用旧服务器版本不支持的 SQL 功能的方式。
某些 MySQL 存储引擎可能支持 SQL 功能,而其他存储引擎则不支持。在这种情况下,提供程序需要使用大多数引擎支持的通用功能子集,或者使用 ProviderManifestToken 来允许您选择。
但是,有缺陷的提供程序也可能只是返回不正确的 SQL。如果是这种情况,那么您必须找到更新或避免触及该错误的查询。
更新:根据@Devart的回答,这似乎是提供商的限制,它是由于MySQL的限制而设计的。 EF 将生成 ADO.NET 规范命令树。提供商有责任将其转换为 SQL。如果 EF 在 CCT 中返回一个跨/外部应用节点,那么 Devart 似乎还没有找到一种方法将其转换为 MySQL 可以处理的 SQL。因此,要么 MySQL 无法胜任支持所有 EF 查询的任务,要么 MySQL 专家(不是我!)需要向 Devart 展示如何生成与 MySQL 兼容的 SQL,该 SQL 可以正确返回交叉/外部应用的行CCT 节点。
If this error is coming from MySQL one of two things have happened:
If this error is coming from your MySQL EF provider, then one of two things have happened:
SQL is generated by the provider. You can configure server-version-specific SQL generation via the ProviderManifestToken attribute in EDMX. This is how you tell the provider not to use SQL features which older server versions don't support.
It's possible that some MySQL storage engines support SQL features which others do not. In this case, the provider would need to either use a common subset of features supported by most engines or use
ProviderManifestToken
to allow you to choose.However, it's also possible that a buggy provider simply returns incorrect SQL. If this is the case then you must either find an update or avoid queries which touch the bug.
Update: Based on @Devart's answer, it seems that this is a limitation of the provider, which is designed in due to limitations of MySQL. The EF will produce an ADO.NET canonical command tree. It is the provider's responsibility to translate this to SQL. If the EF returns a cross/outer apply node in the CCT, it seems that Devart has not found a way to translate this to SQL which MySQL can handle. So either MySQL is just not up to the task of supporting all EF queries, or someone who is a MySQL expert (not me!) needs to show Devart how to produce MySQL-compatible SQL which can properly return rows for the cross/outer apply CCT nodes.
这是实体框架内部架构功能。有时,它会生成 SQL Server 以外的提供程序不支持的查询。更多信息请访问MSDN。
This is an Entity Framework internal architecture feature. Sometimes it generates queries not supported by providers other than SQL Server. More information is available here at MSDN.