Vor diesem Test teilnehmen:Dapper multimapping und links
public class Author
{
public int AuthorId { get; set; }
public List<Book> Books { get; set; } = new List<Book>();
}
public class Book
{
public int BookId { get; set; }
}
[Fact]
public async Task DapperCollapseLeftJoin()
{
var sql = @" select 1 as AuthorId, 1 as BookId
union select 1 as AuthorId, 2 as BookId
union select 2 as AuthorId, 3 as BookId
union select 2 as AuthorId, 4 as BookId";
var authorsWithBooks =
(await AC.OpenConnection.QueryAsync<Author, Book, Author>(sql,
(author, book) => { author.Books.Add(book); return author; },
splitOn: "AuthorId, BookId")).ToList();
// fails because we're getting 4 author+book rows
Assert.Equal(2, authorsWithBooks.Count);
}
Die Dokumentation für Dapper sagt Karten Zeilen auf mehrere Objekte multimapping und erwähnen nicht alles über tatsächlich kollabiert Objekte (wie für links/Inner-Joins passieren würde, wo ganz links Spaltenwerte wiederholen).
Gibt es eine Dapper-native Möglichkeit, dies zu erreichen?