I've got the following mapping working with for key value pairs based on construct using:
Mapper.Initialize(cfg =>
{
cfg.CreateMap<KeyValuePair<MenuTable, List<RoleTable>>,
KeyValuePair<Menu, List<Role>>>()
.ConstructUsing(x =>
new KeyValuePair<Menu, List<Role>>(
Mapper.Map<Menu>(x.Key),
Mapper.Map<List<Role>>(x.Value)
)
);
});
So that I can call it like this:
return Mapper.Map<List<KeyValuePair<Menu, List<Role>>>>(results);
However, this means I need to do this for any time I have such kind of query results. Which could be over 100, and they all use the default flattening for mapping, just in a keyvaluepair collection. How can I make this generic? I haven't quite gotten a grasp on generics in Automapper. The documentation confuses me. I don't see how to declare generic variables.