Using Dapper I have a result set which contains two SQL columns with the same name. How do I read the values?
Both the User
and Skill
table have a column called Name
.
An example of my code:
var query = _connection.Query(@"
select u.*, s.*
from [User] u
left join Skill s ON s.UserID = u.UserID
where Username=@Username",
new { Username }
);
There won't be two name
properties. In my short investigation the result contained the first name but I'm sure this is not guaranteed.
To get both name
's you will need to alias one or both columns in your sql:
var query = _connection.Query(@"
select u.name as user_name, s.name as skill_name
from [User] u
left join Skill s ON s.UserID = u.UserID
where Username=@Username",
new { Username }
);