Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Filtering with Linq.Where

Aperta
#683 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
fsharp, sql
Ambito
databases

Direzione di ricerca

Inizia con l’espressione di query LINQ e l’esempio filterByName nell’issue, quindi riproduci l’SQL generato usando SQLProvider 1.1.91, FSharp.Core 4.7.2 e .NET Core 3.1. Confronta l’alias della tabella usato per il campo Name filtrato con l’SQL previsto; il lavoro è completato quando il filtro punta alla tabella unita prevista senza richiedere il workaround di invertire l’ordine delle tabelle.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
F#
Stelle
627
Fork
147
Merge medio
2h 2m
PR unite (30g)
1

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fsprojects/SQLProvider

Tutte le issue di fsprojects/SQLProvider

Issue simili

Altre issue su Databases

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.