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

SplitOn column is needed twice in the query to work properly

Aperta
#2,155 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp, sql
Ambito
database

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

bug needs-triage

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)

Image

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

Image
This shows TestParentId = 0

Image
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

Image

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

  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 DapperLib/Dapper

Tutte le issue di DapperLib/Dapper

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.