Filtering with Linq.Where
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
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
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fsprojects/SQLProvider
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
fsprojects/SQLProvider#872 · 2 commenti ·
-
Repo Assist? Apertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
fsprojects/SQLProvider#870 · 1 commento ·
-
postgresql
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
fsprojects/SQLProvider#869 · 2 commenti ·
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 42/100
fsprojects/SQLProvider#868 · 2 commenti ·
-
sql server
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
fsprojects/SQLProvider#851 · 1 commento ·
Tutte le issue di fsprojects/SQLProvider
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
AstrBotDevs/AstrBot#10205 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
OHDSI/Data2Evidence#3394 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100