3

I'm trying to use Slapper.AutoMapper alongside Dapper to accomplish something like this: How do I write one to many query in Dapper.Net?.

My POCO is like this:

public class MyEntity
{
    public string Name { get; set; }
    public string Description { get; set; }
    public int Level { get; set; }
    public IList<int> Types { get; set; }
}

And my DB rows returned are like this:

enter image description here

So one entity can have many Types. This is how I map the stuff:

dynamic test = conn.Query<dynamic>(sql); Slapper.AutoMapper.Configuration.AddIdentifier(typeof(MyEntity), "Name");
var testContact = Slapper.AutoMapper.MapDynamic<MyEntity>(test);

However in all my result objects the Types property is null. How can I map all the Type values in to the IList Types?

Community
  • 1
  • 1
Adam Szabo
  • 11,302
  • 18
  • 64
  • 100
  • A stab in the dark here, but have you tried `Slapper.AutoMapper.Configuration.AddIdentifier(typeof(IList), "Types");` – jvanrhyn Jan 17 '16 at 16:27
  • Thanks but that doesn't work like that. The identifier is used to determine DB rows which should be aggregated into the same object graph. So in my case "Name" is the Identifier, since all 3 TestItem1 rows should be aggregated into 1 entity, the Types should be aggregated as a list... – Adam Szabo Jan 17 '16 at 16:34
  • I'm actually trying to do the exact same thing ! I tried to alias the corresponding sql column in the query like so "e.types as Types_" so that slapper tries to map string.empty to the int32 value type. But that makes no sense since slapper seems to be handling only reference type mapping. Did you find any workaround ? – Sbu Feb 13 '16 at 14:04
  • @Simon Budin: No I haven't. I came to the same conclusion that it handles reference type mapping only. I ended up dropping Slapper. Instead I made Dapper return a separate type and I mapped that one to the domain object with the regular AutoMapper. – Adam Szabo Feb 13 '16 at 18:13
  • @AdamSzabo Ok thanks ! Meanwhile I cloned the repo and tweaked it manually but my quick and dirty solution involves boxing on the int type. FYI I created an issue on the repo : https://github.com/SlapperAutoMapper/Slapper.AutoMapper/issues/21 – Sbu Feb 13 '16 at 19:05
  • Ah, forgot to add that I did the aggregation manually before the mapping. Not elegant but I needed something quickly. – Adam Szabo Feb 13 '16 at 22:41

1 Answers1

5

Check the last commit on Slapper.AutoMapper repository...

https://github.com/SlapperAutoMapper/Slapper.AutoMapper/commit/5143308bb94a4951d2db43677f253f4386d1a03c

odelvalle
  • 66
  • 3