1

I've got the following code snippet in a repository class, using Dapper to query and Slapper.Automapper to map:

class MyPocoClass{
    MyPocoClassId int;  
    ...
}

//later:
var results = connection.Query<dynamic>("select MyPocoClassID, ...");
return AutoMapper.MapDynamic<MyPocoClass>(results).ToList();

results above has many items, but the list returned by AutoMapper.MapDynamic has only one item (which is clearly wrong). However, I found that adding the following configuration to AutoMapper fixes the problem:

AutoMapper.Configuration.AddIdentifier(typeof(MyPocoClass), "MyPocoID");

Why does Slapper.AutoMapper need to know the key of my class to simply map a list to another list? Is it trying to eliminate duplicates? I'll also note that this only happens while mapping a certain one of my POCOs (so far)...and I can't figure out why this particular POCO is special.

user1935361
  • 442
  • 3
  • 15

1 Answers1

1

Turns out this is a bug in Slapper.AutoMapper.

The library supports case-insensitive mapping and convention-based keys. The SQL result set has MyPocoClassID and the class itself has MyPocoClassId -- which is not a problem for Slapper.AutoMapper as far as mapping goes. But internally Slapper.AutoMapper identifies (by convention) that MyPocoClass has MyPocoClassId as its identifier, and it can't find that field in the result set. The library uses that key to eliminate duplicates in the output list (for some reason), and since they're all 'null/empty', we get only one record.

I may submit a pull request to fix this problem, but since the library appears to be unmaintained I don't think it'll help.

user1935361
  • 442
  • 3
  • 15