I am having following code
class Program
{
static void Main(string[] args)
{
static void Main(string[] args)
{
DapperExtensions.DapperExtensions.DefaultMapper = typeof(CodeCustomMapper);
string sql = "select UserID,Name as SName , Email ,Email as wmail from dbo.[User]";
using (SqlConnection connection = new SqlConnection(conn))
{
var result = connection.Query<User>(sql
, commandType: CommandType.Text);
}
}
}
public class CodeCustomMapper: ClassMapper<User>
{
public CodeCustomMapper()
{
base.Table("User");
Map(f => f.UserID).Key(KeyType.Identity);
Map(f => f.Name).Column("SName");
Map(f => f.Name).Column("TName");
Map(f => f.EmailID).Column("wmail");
Map(f => f.EmailID).Column("Email");
}
}
Output is coming NULL for manulaly mapped columns.
even though i have assigned default mapper . is it write way of doing ?
any other way of manually mapping database columns with entity properties ?
Please can anybody help
Looks like you are just using a wrong extension method.
Try to use
connection.Get<User>