Search code examples
dapper

Dapper & Multi Column To Property Mapping Is It Possible?


I have a project that I am using Dapper. I have a stored procedure that returns a single row with 2 columns.

var result = connection.Query("sp_Match_Get1Row2Columns", p, commandType: CommandType.StoredProcedure);

What I am wondering is that is there a way rather then create a class to auto map to - can I map those two columns to individual parameters ?

Something like..

var dataA = result.Column1 .....

Thanks


Solution

  • Value-tuples might be useful in this scenario; something like:

    (var id, var name) = connection.QuerySingle<(int, string)>(
        "sp_Match_Get1Row2Columns", p, commandType: CommandType.StoredProcedure);
    // "id" and "name" should now be declared and initialized
    

    should work