c# - How to use AutoMapper to map a list to a dictionary? -


i'm trying merge existing list of objects existing dictionary (and in reverse) list has string id should used key in dictionary. rest of parameters on object in list make object in value field of dictionary.

mapper.createmap<objecta, objectb>(); mapper.createmap<list<objecta>, dictionary<string, objectb>>().?????? 

i've seen ways of doing online none got me way there. reversing (to go dictionary<string, objectb> list<objecta> ideal (i doubt reverse() function me there).

the 2 objects simple types don't have fancy collections in them.

also, there way make mapping fail (throw exception perhaps) if id object in list doesn't exist current key in dictionary?

another 1 of attempts (pseudocode):

objecta.todictionary(key => key.id, value => mapper.map(value, objectb[value.id], typeof(objecta), typeof(objectb))); 

however recreate new dictionary , still need merge in elements original dictionary.

when comes going in reverse found this link looked promising won't compile me:

mapper.createmap<keyvaluepair<string, objectb>, objecta>().constructusing(src => mapper.map<objectb, objecta>(src.key)).formember(dest => dest.id, opt => opt.mapfrom(src.value)); 


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -