Unexpected composed query behavior

Aperta
#732 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
sql
Ambito
databases

Direzione di ricerca

Inizia riproducendo gli esempi di query composte usando DataContext, espressioni tra virgolette e il join mostrato nell’issue. Confronta i valori generati o restituiti per la query con join con quelli delle varianti senza join e con restituzione di tuple; il lavoro è completato quando la query composta con join restituisce gli stessi valori di ParameterId e ParameterName della query diretta.

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

Descrizione

Describe the bug
When using composed queries an unexpected behavior occurs when a join is involved in a query. This results in a select with wrong values. See code examples below.

To Reproduce

let ctx = DataContext.getDataContextWithLog()

// === normal query with expected result
query { 
    for p in ctx.Dbo.Parameters do
    join c in ctx.Dbo.ParametersCategories on 
            (p.CategoryId = c.CategoryId)
    select p
} 
|> Seq.toList
|> List.take 3        
|> List.map (fun p -> p.ParameterId, p.ParameterName)
// Result:
// val it : (int16 * string) list =
//   [(3743s, "Allerg (T1) IgE-totaal"); (3744s, "Allerg (T1) Tryptase");
//    (3745s, "Allerg (T1) Huisstofmijt")]

// === composed query with unexpected result
let get (ctx : DataContext.sql.dataContext) =
    <@ fun _ ->
        query { 
            for p in ctx.Dbo.Parameters do
            join c in ctx.Dbo.ParametersCategories on 
                    (p.CategoryId = c.CategoryId)
            select (p)
        } @>

query {
for (p) in ((%get ctx) ()) do
    select (p.ParameterId, p.ParameterName)
}
|> Seq.toList
|> List.take 3        
// Result:
// val get :
//   ctx:FSharp.Data.Sql.SqlDataProvider<...>.dataContext ->
//     Quotations.Expr<('a ->
//                        Linq.IQueryable<FSharp.Data.Sql.SqlDataProvider<...>.dataContext.dbo.ParametersEntity>)>
// val it : (int16 * string) list = [(0s, ""); (0s, ""); (0s, "")]

// == composed query without join with expected result
let get (ctx : DataContext.sql.dataContext) =
    <@ fun _ ->
        query { 
            for p in ctx.Dbo.Parameters do
            // join c in ctx.Dbo.ParametersCategories on 
            //         (p.CategoryId = c.CategoryId)
            select (p)
        } @>

query {
for (p) in ((%get ctx) ()) do
    select (p.ParameterId, p.ParameterName)
}
|> Seq.toList
|> List.take 3        
// Result:
// val get :
//   ctx:FSharp.Data.Sql.SqlDataProvider<...>.dataContext ->
//     Quotations.Expr<('a ->
//                        Linq.IQueryable<FSharp.Data.Sql.SqlDataProvider<...>.dataContext.dbo.ParametersEntity>)>
// val it : (int16 * string) list =
//   [(3743s, "Allerg (T1) IgE-totaal"); (3744s, "Allerg (T1) Tryptase");
//    (3745s, "Allerg (T1) Huisstofmijt")]

// == composed query with a tuple return with a 'dummy' unit value returns expected result!?
let get (ctx : DataContext.sql.dataContext) =
    <@ fun _ ->
        query { 
            for p in ctx.Dbo.Parameters do
            join c in ctx.Dbo.ParametersCategories on 
                    (p.CategoryId = c.CategoryId)
            select (p, ())
        } @>

query {
for (p, _) in ((%get ctx) ()) do
    select (p.ParameterId, p.ParameterName)
}
|> Seq.toList
|> List.take 3        
// Result:
// val it : (int16 * string) list =
//   [(3743s, "Allerg (T1) IgE-totaal"); (3744s, "Allerg (T1) Tryptase");
//    (3745s, "Allerg (T1) Huisstofmijt")]

Expected behavior
Clearly the second query result is inconsistent with the other queries.

Desktop (please complete the following information):
.NET SDK (reflecting any global.json):
Version: 5.0.202
Commit: db7cc87d51

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.202\

Host (useful for support):
Version: 5.0.5
Commit: 2f740adc14

.NET SDKs installed:
5.0.200-preview.21077.7 [C:\Program Files\dotnet\sdk]
5.0.201 [C:\Program Files\dotnet\sdk]
5.0.202 [C:\Program Files\dotnet\sdk]

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.