Automapper mapping returns Zeroed values

Asked

Viewed 40 times

0

I have the following problem, when executing a query of a procedure, its response to being mapped returns the values of the properties with null value.

My Datareader with Automapper Mapping

public List<T> DataReader<T>(string Procedure, List<SqlParameter> parameters)
{
    var rows = ExecuteProcedureReader(Procedure, parameters);

    if(rows.HasRows)
    {
        var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; cfg.AddDataReaderMapping(); });
        var mapper = config.CreateMapper();

        return mapper.Map<IDataReader, List<T>>(rows);
    }

    return null;
}

The call of the method

var lista = conn.DataReader<Usuario>("PR_USUARIO_CONSULTAR", param);

foreach (var item in lista)
{
    Console.WriteLine(item.Nome);
}

My Class

public class Usuario
{
    public int Codigo { get; set; }

    public string Nome { get; set; }

    public string Emdereco { get; set; }

    public string Cpf { get; set; }
}

How can I make Automapper to map all records dynamically.

Note: I am using beyond the Automapper, the Automapper.Data

  • Dude, it’s kind of confusing your logic, because you put Return there inside the while?

  • @Lucasmiranda opa is even actually is a if , but the problem continues. It does not map bank properties with the model.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.