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 class System.Reflection.Emit.Typebuilder to generate a type at runtime.
I use Dapper to take the data in 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 map the classGerada to classGerada2, 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 suggestion). I’m using the following mapping:
AutoMapper.Mapper.Initialize(f => f.CreateMap(targetClass, sourceClass)
.ForMember("Sequencial", m => m.MapFrom("TabelaId")));
When I execute
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=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089]] -> System Type.
*sourceClass is the type generated at runtime from the data dictionary.
Can anyone say what is wrong? Or what would be the way to do it?
I believe the error is by the type generated at runtime that is a
Object
and can’t get to the guy that’s it...!– novic
@Virgilionovic how do I fix it then? The class needs to be dynamic, and I need to generate it from the data dictionary. But I need to map the same result to two different objects that only have two properties in comun.
– Renatto Machado
@I believe https://github.com/AutoMapper/AutoMapper/wiki/Dynamic-and-ExpandoObject-Mapping has an example of something that can help you, because in your question there is no way to generate a minimal example, you could put the example in full?
– novic
You managed to make it work without trying to use the
TypeBuilder
? That is, creating a class on the same hand, creating the target class in hand as well, and trying to use Auto Mapper? Try to make it work like this first.... then try to use dynamically. Apparently the classtargetClass
has some kind PropertyIEnumerable
that does not exist in thesourceClass
. Since we don’t know how both types are (both classes), we can’t help much. Only if someone has tried this and gone through the same problem.– Alisson