Search code examples
c#automappernpoco

Why is AutoMapper not mapping from NPoco dynamic object to entity?


When I do an NPoco fetch

var products = db.Fetch<dynamic>(sql).ToArray();

and then try to map it with AutoMapper

Mapper.Map<Product[]>(loc)

The resulting Product does not have any of the expected values even though

  • The names and case of the column names in sql, the NPoco.PocoExpando instances in products, and the Product class, and they all match.
  • The values in the expando are correct for each column.
  • The setters in Product are public.

The AutoMapper documentation suggests that I'm doing everything correctly. Is this a bug or am I missing something?


Solution

  • In my call to Mapper.Initialize I set IMapperConfigurationExpression.CreateMissingTypeMaps to true. It seems that doing this interferes with the dynamic mapping.