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
- 分支
- 148
- 平均合併
- 2 小時 2 分鐘
- 30 天內合併 PR
- 1
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 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
-
area:connection bug effort:S priority:P2
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
Arekkazu/sgpmp-backend#549 ·
維護者通常 1 天內回覆
-
priority: medium tech-debt
難度 2/5 1-3 小時 新手友好度 62/100
LeeAdcock/robocodeJs.com#411 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
good first issue refactor
難度 2/5 1-3 小時 新手友好度 80/100
pedrorchagas/blog-api#18 ·