Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Filtering with Linq.Where

オープン
#683 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
fsharp, sql
領域
databases

調査の方向性

Issue の LINQ query expression と filterByName の例から始め、SQLProvider 1.1.91、FSharp.Core 4.7.2、.NET Core 3.1 を使用して生成された SQL を再現します。フィルターされた Name フィールドに使用されているテーブルエイリアスを期待される SQL と比較します。フィルターが意図した結合先テーブルを対象とし、テーブルの順序を逆にする workaround を必要としなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

question

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分
マージ済み PR(30日)
1

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fsprojects/SQLProvider のほかの issue

fsprojects/SQLProvider の issue をすべて見る

似ている issue

Databases の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。