kurabdurbos
kurabdurbos

Reputation: 277

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

Upvotes: 2

Views: 68

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062502

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

Upvotes: 1

Related Questions