我正在使用自定义查询提供程序,并希望支持SQL Server's recursive CTEs。我有一些我认为会起作用的东西,但我想做两件改进。
首先,这是我的查询运算符的签名(主要基于GroupJoin
)。
type QueryBuilder with
[<CustomOperation("recurse", IsLikeGroupJoin = true, JoinConditionWord = "on")>]
member x.Recurse(
anchorSource: QuerySource<'Anchor, 'Q>,
recursiveSource: QuerySource<'Recursive, 'Q>,
anchorKeySelector: ('Anchor -> 'Key),
recursiveKeySelector: ('Recursive -> 'Key),
resultSelector: ('Anchor -> IQueryable<'Recursive> -> 'Result)) =
Unchecked.defaultof<QuerySource<'Result, 'Q>>
这是一个示例查询。注意评论。我想要做的第一个改进是之前的范围变量不应该是可访问的。这可能吗?
query {
for x in customQueryable do
where (x.Day = 5)
recurse y in customQueryable
on (x.Subtract(TimeSpan.FromDays 1.0) = y) into g
for z in g do
//NOTE: `x` shouldn't be in scope here
select x
}
第二个改进是,我更喜欢使用下面的查询语法,但无法弄清楚如何将其拉下来。
query {
for x in customQueryable do
where (x.Day = 5)
for y in customQueryable do
recurseOn (x.Subtract(TimeSpan.FromDays 1.0) = y) into g
for z in g do
select z
}
我也想知道这是否可能。