I have a scenario where I need to return a single column as part of a multi map query in Dapper.
I've simplified the example below but in essence the single column value (the int) I want to retrieve is not a property on the Post class (but is in the database table).
I want to fetch this value on it's own as use it in a manner similar to the following line from the example, where status is the int value in question:
post.SetSomeStatus(status);
Here is the code example:
var sql =
@"select *, p.Status from #Posts p
left join #Users u on u.Id = p.OwnerId
Order by p.Id";
var data = connection.Query<Post, User, int, Post>(sql, (post, user, status) => {
post.Owner = user;
post.SetSomeStatus(status);
return post;
});
var post = data.First();
I'm seeing the following error with this code: Index was outside the bounds of the array.