Applying automapper

0

Hi, I have a method in which I apply automation but I get the following error: Unable to convert the DGVdto type with SupplierExtend implicitly If both have the same properties.

public class ProveedorExtend 
{
    public int Id { get; set; }
    public string Descripcion { get; set; }
}
public class DGVdto
{
    public int Id { get; set; }
    public string Descripcion { get; set; }
}

Why the error is

public List<ProveedorExtend> GetProveedor()
    {
        List<ProveedorExtend> _proveedor = _sdproveedor.GetProveedor();
        List<DGVdto> listDto = Mapper.Map<List<ProveedorExtend>, List<DGVdto>>(_proveedor);
        return **listDto**; Error arriba en mención.
    }

This is the new method

public List<DGVdto> GetProveedor()
    {
        List<ProveedorExtend> _proveedor = _sdproveedor.GetProveedor();
        config = new MapperConfiguration(cfg => cfg.CreateMap<ProveedorExtend, DGVdto>());
        List<DGVdto> listDto = config.CreateMapper().Map<List<DGVdto>>(_proveedor);
        return listDto;
    }

_provider brings records, but I can not pass them to listDto, what am I doing wrong? ListDto comes empty.

    
asked by Pedro Ávila 26.04.2016 в 20:03
source

1 answer

2

As you will see in the example

MapperConfiguration config;
private void Form1_Load(object sender, EventArgs e)
{
    config = new MapperConfiguration(cfg => cfg.CreateMap<ProveedorExtend, DGVdto>());

}

public List<DGVdto> GetProveedor()
{
    List<ProveedorExtend> _proveedor = new List<ProveedorExtend>();

    List<DGVdto> listDto = config.CreateMapper().Map<List<DGVdto>>(_proveedor);

    return listDto;
}

how to map change in the latest versions.

In the Map<>() if you define input%% of% the output can not be the same, so change the type returned by the method List<ProveedorExtend>

Getting Started Guide

    
answered by 26.04.2016 / 20:32
source