SplitOn column is needed twice in the query to work properly
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Inizia dal percorso di multi-mapping di QueryAsync di Dapper e dalla gestione di splitOn, quindi riproduci l’esempio SQL Server fornito con gli oggetti TestChild e TestParent. Confronta il comportamento quando TestParentId viene selezionato una volta rispetto a due volte; il lavoro è completo quando la singola colonna di split documentata conserva il TestParentId dell'elemento figlio, con un test di regressione che copra il caso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hello,
I'm using Dapper 2.1.66 with SQL Server and Net 8.
I noticed a weird thing using the SplitOn feature where it doesn't work as expected.
I created a basic test case to demonstrate the issue.
I have created 2 basic tables with just a few columns in each:
- TestParent: TestParentId, TestParentNm
- TestChild: TestChildId, TestParentId, PermissionId
I use this query to pull the data:
Select p.TestChildId, p.PermissionId, p.TestParentId, r.TestParentNm
From TestChild p inner join TestParent r ON p.TestParentId = r.TestParentId
As shown in the Dapper SplitOn example page, I only select the join column once (see: https://www.learndapper.com/relationships#dapper-spliton)
This gives this result (in green, child columns, in blue, parent columns)
Now, in my code, when I want to query the data and populate my objects, I use this code:
var query = "Select p.TestChildId, p.PermissionId, p.TestParentId, r.TestParentId, r.TestParentNm " +
"From TestChild p inner join TestParent r ON p.TestParentId = r.TestParentId";
var itemList = (await dbDapperHelper
.GetDapperConnection()
.QueryAsync<TestChild, TestParent, TestChild>(
query, (child, parent) => {
child.TestParent = parent;
return child;
},
new { },
splitOn: "TestParentId"))
.ToList();
GetDapperConnection() is a helper method that returns the SqlConnection
Ok, now the weird thing.
When I run this code, I'm able to populate "TestParent" with the parent object, but the TestParentId of the child object remains 0
This shows TestParentId = 0
But here you can see that the TestParent object is populated, and has a TestParentId of 4.
I would expect the TestParentId in the child to be 4 too.
Now, if I modify the SQL query to output the TestParentId column twice, it works as expected
This strikes me as weird, since the example in the official Dapper documentation shows that the splitOn column needs to be in the output columns only once.
Is there something in my set up that is wrong?
Let me know if you need more details
Thanks
- Lingua principale
- C#
- Stelle
- 18.4k
- Fork
- 3.7k
- Merge medio
- 2g 5h
- PR unite (30g)
- 4
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 DapperLib/Dapper
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
-
Dapper.Rainbow uses DbConnection on Init instead of IDbConnectionForse già presa @Khaos66 l’ha presa 1559 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
-
Dapper.StrongName 2.1.86 fails strong-name signature verification (all TFMs) — works in 2.1.79Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
Tutte le issue di DapperLib/Dapper
Issue simili
-
area:jobads-cv BE mvp P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
klasolsson81/jobbliggaren#2099 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
0 - Backlog Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
BrighterCommand/Brighter#4581 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
Esri/calcite-dotnet-toolkit#30 · 1 reazione ·
-
kind:docs simplification size:S status:todo
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
elsa-workflows/elsa-foundation#2604 ·
I maintainer di solito rispondono entro 1 giorno