c# – Erro no mapeamento dinâmico: Missing type map configuration or unsupported mapping


I have a data dictionary that looks 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 from the database and generate a variable with the table type, for example:

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

Now I would like to make a mapping fromGenerateclass toGenerate2class, the difference between the two is that one has only two columns and the other has all columns.

I'm trying to do this using AutoMapper (I didn't find how to do it in another library, I accept a 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 map configuration or unsupported mapping.

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

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

Can anyone tell what's wrong? Or what would be the way to do this?


You need to configure the types you want to map before, try using the code below:

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

Obs.: Replace the TipoTargetClass and TipoSourceClass texts for the correct type of your objects.

Scroll to Top