c# - AutoMapper not mapping sub property -
i receiving issue automapper v6.0.2 automapper trying shove icollection int instead of specified collection.
error:
mapping types: member_b3b146ab4f61aede3df3639bdbd65bfa5bca0fc414f11960dc39da834f2a8cbd -> icollection`1 system.data.entity.dynamicproxies.memberr_b3b146ab4f61aede3df3639bdbd65bfa5bca0fc414f11960dc39da834f2a8cbd -> system.collections.generic.icollection`1[[memberservice.dto.dependentdetaildto, memberservice, version=1.0.0.0, culture=neutral, publickeytoken=null]] destination path: memberdetaildto.dependents.dependents source value: system.data.entity.dynamicproxies.mbmrostersubscriber_b3b146ab4f61aede3df3639bdbd65bfa5bca0fc414f11960dc39da834f2a8cbd ---> system.overflowexception: value either large or small int32. member
public member () { this.dependents = new hashset<dependent>(); } public virtual icollection<dependent> dependents { get; set; } automapper config
createmap<dependent, dependentdetaildto>(); createmap<member, memberdetaildto>() .formember(a => a.dependents, o => o.mapfrom(x => mapper.map<icollection<dependent>, icollection<dependentdetail>>(x.dependents))); dependent:
public string title { get; set; } public string firstname { get; set; } public string lastname { get; set; } public string middlename { get; set; } public system.datetime dob { get; set; } public string sex { get; set; } public string relationship { get; set; } public string createdby { get; set; } public string modifiedby { get; set; } public string departmentcode { get; set; } public string address1 { get; set; } public string address2 { get; set; } public string address3 { get; set; } public string city { get; set; } public string state { get; set; } public string mailcountry { get; set; } public string zip { get; set; } public nullable<system.datetime> ssnencryptdate { get; set; } when dependents removed subscriber maps perfectly
as dependent entity , model copy , paste items public. appears if automapper trying squeeze collection int instead of specified map.
any ideas?
dependents navigation property
edit : being tested in functional test in async method. quick unit test has been created:
[testmethod] public void retrieveactivemember() { memberentity.member subscriber = new member(); icollection<dependent> dependent = new list<dependent>(); dependent.add(new dependent { hostcountry = "home" }); subscriber.dependents = dependent; var mapped = automapper.mapper.map<member, memberdetaildto>(subscriber); assert.isnotnull(mapped); } error being returned method 'add' in type x not have implementation'
property: dependents ---> system.typeloadexception: method 'add' in type 'proxy<system.collections.generic.icollection`1[[memberservice.dto.dependentdetaildto_memberservice_version=1.0.0.0_culture=neutral_publickeytoken=null]]_mscorlib_version=4.0.0.0_culture=neutral_publickeytoken=b77a5c561934e089>' assembly 'automapper.proxies, version=0.0.0.0, culture=neutral, publickeytoken=be96cd2c38ef1005' not have implementation. changing automapper config dependent to
createmap<icollection<dependent>, icollection<dependentdetaildto>>() .constructusing((icollection<dependent> dependents) => { list<dependentdetaildto> dependentlist = new list<dependentdetaildto>(); foreach (var dependent in dependents) dependentlist.add(new dependentdetaildto { }); return dependentlist; }); makes unit test work albeit no longer using automapper big caveat, still breaks on functional test
i can't think of else add dependents not have integer field
addendum: entity, dto, , caller in different libraries have not been able replicate in .netfiddle
automapper should handle collections you. known maps might apply, no need call mapper.map inside mapfrom.
just define maps individual entities:
createmap<dependent, dependentdetaildto>(); createmap<member, memberdetaildto>() .formember(dto => dto.dependents, o => o.mapfrom(src => src.dependents);
Comments
Post a Comment