Error in dynamic mapping: Missing type mapping or unsupported mapping

3

I have a data dictionary something like this:

public class Colunas 
{
   public string ColunaOrigem {get; set;}
   public string ColunaDestino {get; set;}
   public DbType Tipo {get; set;}
}

public class Tabela
{
   public string Nome {get; set;}
   public IList<Coluna> Colunas {get; set;}
}


var dicionarioDados = new Tabela();

I use the System.Reflection.Emit.TypeBuilder class to generate a type at runtime.

I use Dapper to get the data in the database and generate a variable with the type of the table, for example:

var resultado = connection.Query(typeof(classeGerada), "select * from Tabela");

Now I would like to do a mapping of the class Generated to classGenerate2, the difference of the two is that one only has two columns and the other one has all the columns.

I'm trying to do this using AutoMapper (I did not figure out how to do it in another library, I accept suggestion). I'm using the following mapping:

AutoMapper.Mapper.Initialize(f => f.CreateMap(targetClass, sourceClass)
                      .ForMember("Sequencial", m => m.MapFrom("TabelaId")));

When I run

var resultadoMapeado = Mapper.Map(resultado , sourceClass);

I have the following error:

  

Missing type mapping or unsupported mapping.

     

Mapping types: IEnumerable'1 - > Type   System.Collections.Generic.IEnumerable'1 [[System.Object, mscorlib,   Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089]] - >   System.Type

* sourceClass is the type generated at runtime from the data dictionary.

Does anyone know what's wrong? Or what would be the way to do it?

    
asked by anonymous 21.08.2017 / 15:22

1 answer

2

You must first configure the types you want to map, try using the code below:

    private static IMapper mapper = new MapperConfiguration(cfg => {
        cfg.CreateMap<TipoTargetClass, TipoSourceClass>();
    }).CreateMapper();

Note: Replace the TypeTargetClass and TypeSourceClass texts for the correct type of your objects.

    
16.10.2017 / 02:11