Filtering with Linq.Where
还没有人认领这个 Issue。
评估
调研方向
从 issue 中的 LINQ 查询表达式和 filterByName 示例开始,然后使用 SQLProvider 1.1.91、FSharp.Core 4.7.2 和 .NET Core 3.1 重现生成的 SQL。将用于已过滤 Name 字段的表别名与预期的 SQL 进行比较;完成的标准是过滤器指向预期的连接表,而不需要通过反转表顺序这一 workaround。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Trying to execute a join and filtering using Linq.Where on the second table produces a sql where clause where the field is linked to the first table not the second one.
To Reproduce
let filterByName (filter: Filter): Filtering =
fun q ->
match filter.Name with
| ValueNone -> q
| ValueSome n -> n |> Str.value |> (fun v -> q.Where(fun e -> e.Name.Contains(v)))
let search: Insurer.Query.DbSearch =
fun (tenantId, filter) ->
let tenantId = tenantId |> TenantId.value
let ctx = Db.readerCtx ()
query {
for i in ctx.Insurance.InsurerTable do
join c in ctx.People.Company on
((i.TenantId, i.PersonId) = (c.TenantId, c.Id))
where
(c.TenantId = tenantId)
select c
}
|> filterByName filter
generates the following sql clause:
SELECT [Column List]
FROM [Insurance].[InsurerTable] as i
INNER JOIN [People].[Company] as c
on i.[TenantId] = c.[TenantId] AND i.[PersonId] = c.[Id]
WHERE ((c.[TenantId] = 561) AND (c.[Name] LIKE N'%Name209092560%'))
Expected behavior
SELECT [Column List]
FROM [Insurance].[InsurerTable] as i
INNER JOIN [People].[Company] as c
on i.[TenantId] = c.[TenantId] AND i.[PersonId] = c.[Id]
WHERE ((c.[TenantId] = 561) AND (i.[Name] LIKE N'%Name209092560%'))
Please, note the expected clause uses i.[Name] instead of c.[Name] in WHERE section.
Additional context
SQLProvider (1.1.91)
FSharp.Core (4.7.2)
Net Core 3.1
Workaround for this particular case
Inverting the order of the tables in the query solves the problem:
for c in ctx.People.Company do
join i in ctx.Insurance.InsurerTable on
((c.TenantId, c.Id) = (i.TenantId, i.PersonId))
But this is valid in this case, in many others, this solution won't be possible.
- 主要语言
- F#
- 星标
- 627
- 派生
- 147
- 平均合并
- 2 小时 2 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fsprojects/SQLProvider 的其他 Issue
-
enhancement
难度 3/5 1-2 天 新手友好度 55/100
fsprojects/SQLProvider#872 · 2 条评论 ·
-
Repo Assist? 未关闭enhancement
难度 5/5 一周以上 新手友好度 10/100
fsprojects/SQLProvider#870 · 1 条评论 ·
-
postgresql
难度 4/5 3-5 天 新手友好度 58/100
fsprojects/SQLProvider#869 · 2 条评论 ·
-
documentation
难度 2/5 1-3 小时 新手友好度 42/100
fsprojects/SQLProvider#868 · 2 条评论 ·
-
sql server
难度 4/5 3-5 天 新手友好度 45/100
fsprojects/SQLProvider#851 · 1 条评论 ·
查看 fsprojects/SQLProvider 的全部 Issue
相似的 Issue
-
channels:add check:passed
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 70/100
confluentinc/dbt-confluent#160 ·
-
难度 1/5 1 小时以内 新手友好度 75/100
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
AstrBotDevs/AstrBot#10205 ·
-
难度 2/5 1-3 小时 新手友好度 72/100