实体框架中的CTE Sql查询支持<definingquery> </definitionsquery>

时间:2011-01-05 01:53:15

标签: c# entity-framework linq-to-entities sql

实体框架可以支持在

中使用CTE /行号的SQL查询
<DefiningQuery> </DefiningQuery>
<。> .edmx文件的属性?

这是针对本帖子中使用此类功能的查询:Complex / Algorithmic SQL Query

我从sql获得以下InnerException:

Incorrect syntax near the keyword 'with'.
Incorrect syntax near the keyword 'with'. If this statement is a common table ex
pression, an xmlnamespaces clause or a change tracking context clause, the previ
ous statement must be terminated with a semicolon.
Incorrect syntax near ','.
Incorrect syntax near ','.
Incorrect syntax near ')'.

在打开'with'语句之前添加分号并不能解决问题。它说';'附近的语法不正确在这种情况下。

如果不支持,我想我可以将存储过程绑定到复杂的实体,但还有其他选项吗?

感谢。

1 个答案:

答案 0 :(得分:0)

此帖子未指定CTE是递归还是非递归。可能有令人信服的性能原因使用递归CTE,这可能超过抽象数据库的愿望(即使用EF作为ORM)。

在实体框架4中,有一些解决方法,正如Martin在上面提到的那样使用视图。这篇博文来自Matthieu Mezil(http://msmvps.com/blogs/matthieu/archive/2010/06/16/how-to-include-recursion-table-valued-functions-in-linq-to-entities-queries-with-ef4.aspx) 有关于如何做到这一点的一些非常详细的信息。