Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:57:14+00:00 2026-05-22T11:57:14+00:00

Playing around with Dapper, I’m quite pleased with the results so far – intriguing!

  • 0

Playing around with Dapper, I’m quite pleased with the results so far – intriguing!

But now, my next scenario would be to read data from two tables – a Student and an Address table.

Student table has a primary key of StudentID (INT IDENTITY), Address has an AddressID (INT IDENTITY). Student also has an FK called AddressID linking into the Address table.

My idea was to create two classes, one for each table, with the properties I’m interested in. Additionally, I put an PrimaryAddress property of type Address onto my Student class in C#.

I then tried to retrieve both student and address data in a single query – I mimick the sample that’s given on the Github page:

var data = connection.Query<Post, User>(sql, (post, user) => { post.Owner = user; });
var post = data.First();

Here, a Post and a User are retrieved, and the owner of the post is set to the user – the type returned is a Post – correct?

So in my code, I define two parameters to the generic Query extension method – a Student as the first which should be returned, and an Address as the second, which will be stored onto the student instance:

var student = _conn.Query<Student, Address>
                  ("SELECT s.*, a.* FROM dbo.Student s 
                        INNER JOIN dbo.Address a ON s.AddressID = a.AddressID 
                        WHERE s.StudentenID = @Id", 
                    (stu, adr) => { stu.PrimaryAddress = adr; },  
                    new { Id = 4711 });

Trouble is – I get an error in Visual Studio:

Using the generic method
‘Dapper.SqlMapper.Query(System.Data.IDbConnection,
string,
System.Func,
dynamic, System.Data.IDbTransaction,
bool, string, int?,
System.Data.CommandType?)’ requires 6
type arguments

I don’t really understand why Dapper insists on using this overload with 6 type arguments…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:57:15+00:00Added an answer on May 22, 2026 at 11:57 am

    That would be cause I changed APIs and forgot to update the documentation, I corrected the error.

    Be sure to have a look at Tests.cs for a full up-to-date spec.

    In particular, the old API used to take in an Action<T,U> to perform the mapping, the trouble was that it felt both arbitrary and inflexible. You could not fully control the return type. The new APIs take in a Func<T,U,V>. So you can control the type you get back from the mapper and it does not need to be a mapped type.

    I just tied up some additional flexibility around multi mapping, this test should make it clear:

    class Person
    {
        public int PersonId { get; set; }
        public string Name { get; set; }
    }
    
    class Address
    {
        public int AddressId { get; set; }
        public string Name { get; set; }
        public int PersonId { get; set; }
    }
    
    class Extra
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    
    public void TestFlexibleMultiMapping()
    {
        var sql = 
    @"select 
    1 as PersonId, 'bob' as Name, 
    2 as AddressId, 'abc street' as Name, 1 as PersonId,
    3 as Id, 'fred' as Name
    ";
        var personWithAddress = connection.Query<Person, Address, Extra, Tuple<Person, Address,Extra>>
            (sql, (p,a,e) => Tuple.Create(p, a, e), splitOn: "AddressId,Id").First();
    
        personWithAddress.Item1.PersonId.IsEqualTo(1);
        personWithAddress.Item1.Name.IsEqualTo("bob");
        personWithAddress.Item2.AddressId.IsEqualTo(2);
        personWithAddress.Item2.Name.IsEqualTo("abc street");
        personWithAddress.Item2.PersonId.IsEqualTo(1);
        personWithAddress.Item3.Id.IsEqualTo(3);
        personWithAddress.Item3.Name.IsEqualTo("fred");
    
    }
    

    Dapper pipes all the multi mapping APIs through a single method, so if something fails it will end up in the 6 param one. The other piece of the puzzle was that I did not allow for some super flexible splits, which I just added.

    Note, the splitOn param will default to Id, meaning it will take a column called id or Id as the first object boundary. However if you need boundaries on multiple primary keys that have different names for say a “3 way” multi mapping, you can now pass in a comma separated list.

    So if we were to fix the above, probably the following would work:

     var student = _conn.Query<Student,Address,Student>
                  ("SELECT s.*, a.* FROM dbo.Student s 
                        INNER JOIN dbo.Address a ON s.AddressID = a.AddressID 
                        WHERE s.StudentenID = @Id", 
                    (stu, adr) => { stu.PrimaryAddress = adr; return stu;},  
                    new { Id = 4711 }, splitOn: "AddressID").FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just playing around with the now released Silverlight 2.0. I'm trying to put a
I'm playing around with LinqToSQL using an existing multi-lingual database, but I'm running into
I'm playing around with BCEL. I'm not using it to generate bytecode, but instead
While playing around with regexps in Scala I wrote something like this: scala> val
I'm currently playing around with HTML_QuickForm for generating forms in PHP. It seems kind
I'm playing around with the <canvas> element, drawing lines and such. I've noticed that
I'm playing around with a native (non-web) single-player game I'm writing, and it occured
Hallo i am currently playing around with castle projects ActiveRecord and the remoting facility.
I was playing around with my own Sudoku solver and was looking for some
I am playing around with MVC and have started setting up an existing site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.