Automapper: Mapping a property value of an object to a string?

Up vote 0 down vote favorite share g+ share fb share tw.

Using Automapper, how do you handle the mapping of a property value on an object to an instance of a string. Basically I have a list of Role objects and I want to use Automapper to map the content of each "name" property to a corresponding list of string (so I just end up with a list of strings). I'm sure it has an obvious answer, but I can't find the mapping that I need to add to "CreateMap" to get it to work.

An example of the relevant code is shown below: public class Role { public Guid Id{get;set;} public string Name{get;set;} ... ... } // What goes in here? Mapper.CreateMap(). ForMember(....); var allRoles = Mapper.

Map, IList>(roles); automapper link|improve this question asked Dec 14 '10 at 13:58Paul Hadfield2,7211317 92% accept rate.

Var allRoles = from r in roles select r.Name.

In this instance you are probably right and it would fit in with our infrastructure, but even so I'd be interested in knowing if/how it could be done with Automapper. – Paul Hadfield Dec 14 '10 at 14:35 1 Sorry -- should have answered your original question. :) This should work: Mapper.CreateMap().

ConvertUsing(r => r. Name); – Patrick Steele Dec 14 '10 at 15:17 Thanks for providing an Automapper way of doing this, it works exactly as I'd hoped. – Paul Hadfield Dec 15 '10 at 11:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions