I have a simple Poco
public virtual short UserID
{
get;
set;
}
[Required]
public virtual string UserName
{
get;
set;
}
public virtual string Password
{
get;
set;
}
public virtual string Email
{
get;
set;
}
Im currently Using Dapper ORM.
Does anyone have a good example of how I would query using dapper ORM to create a drop-down-list?
The query should return Key=UserID and Value=UserName in a list so that I can retrieve the keys and populate the DropDownList.
you can create a class representing the pair:
you use the aliases to map the table fields to the class properties names. I’m supposing your table field names are
idandUserName, change them according to your case.You should also pay attention to the property types, you can have a bad cast exception if they don’t match.
ALternatively, you can use the dynamic version:
you obtain a list of dynamics each with property named Key and UserName.