c# - Mapping A Property Of List<T> Using Automapper -
using automapper, want map property list of type employee using string.join() product comma-delimited string of names of employee's rights. here classes i'm using:
public class mappedemployee { public string name { get; set; } public string rightnames { get; set; } } public class employee { public string name { get; set; } public list<right> rights { get; set; } } public class right { public string name { get; set; } }
and here code have:
mapper.createmap<employee, mappedemployee>() .formember(d => d.rightnames, o => o.mapfrom(s => s.rights.selectmany(r => string.join(", ", r.name)))); var employee = new employee { name = "joe schmoe", rights = new list<right> { new right { name = "admin" }, new right { name = "user" }, } }; var mappedemployee = mapper.map<employee, mappedemployee>(employee);
however, it's producing folowing:
system.linq.enumerable+<selectmanyiterator>d__14`2[employee.right,system.char]
what can do comma-delimited string of employee's rights?
try using resolveusing
instead , putting string.join
before selection:
mapper.createmap<employee, mappedemployee>() .formember(d => d.rightnames, o => o.resolveusing(s => string.join(", ",s.rights.select(r => r.name))));
Comments
Post a Comment