0

I am trying to use Automapper on properties with different names. Is there a better way to do this than to individually map each property to another?

public class User
{
    public string Name { get; set; }
    public int age { get; set; }
}

public class bruker
{
     public string navn { get; set; }
     public int alder { get; set; }
}
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
user3044294
  • 205
  • 1
  • 15
  • Out of curiosity, have you actually Googled (or Binged) your title? You may be interested ;) – Metro Smurf Jan 11 '14 at 02:58
  • You would be better off if the property names of the target and destination objects were identical that is where time is really saved. – Ross Bush Jan 11 '14 at 03:01
  • 1
    @lrb: well yeah obviously, but the entire question is what to do if that isn't the case. – Jeroen Vannevel Jan 11 '14 at 03:04
  • Thanks for every one. i show only an example. in my case i have a more than 50 different properties. – user3044294 Jan 11 '14 at 04:42
  • without useing following line in 50 times. how can i do this .thank you Mapper.CreateMap() .ForMember(dest => dest.name, opt => opt.MapFrom(src => src.navn)); – user3044294 Jan 11 '14 at 04:43
  • The "duplicates" are all about the alternative the OP clearly states not to aim at. This is about a kind of global mapping, as in `navn` will always, anywhere be mapped to `Name`. Not that I think AutoMapper can do this, but it's a different question. Voting to reopen. – Gert Arnold Jan 12 '14 at 09:17

0 Answers0