gpt4 book ai didi

c# - Entity Framework 中的 CTE Sql 查询支持

转载 作者:太空宇宙 更新时间:2023-11-03 16:49:26 26 4
gpt4 key购买 nike

Entity Framework 能否支持在

中使用 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”语句前添加分号不能解决问题。它说 ';' 附近的语法不正确在这种情况下。

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

谢谢。

最佳答案

这篇文章没有具体说明 CTE 是递归的还是非递归的。使用递归 CTE 可能有令人信服的性能原因,这可能超过抽象数据库的愿望(即使用 EF 作为 ORM)。

在 Entity Framework 4 中,有 Martin 在上面提到的使用 View 的解决方法。来自 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 ) 的这篇博文有一些关于如何做到这一点的详细信息。

关于c# - Entity Framework 中的 CTE Sql 查询支持 <DefiningQuery>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4600185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com