DapperExtensions DefaultMapper not working

asp.net-mvc-4 dapper

Question

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

Accepted Answer

Looks like you are just using a wrong extension method.

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs.

Try to use connection.Get<User>




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why