8

From similar questions on here I have read here that AutoMapper used to be case sensitive, but is now case insensitive. I want it case sensitive - can't see any way to change this, and none of the other questions Re this showed how to do it (I did look). Any ideas anyone?

Thanks

wakjah
  • 4,541
  • 1
  • 18
  • 23
RBrowning99
  • 411
  • 2
  • 9
  • 21
  • Is there any reason you can't use `.ForMember` when creating the maps? – Pete Garafano Dec 19 '13 at 19:54
  • I don't believe I can - the maps are generated by a T4 template which just iterates over the columns. The problem I had was I had renamed a navigation propery and mistakenly given it the same name (albeit different case) as a regular property. By setting CLSCompliant(true) and promoting that warning to an error I now get a compilation error which is better than nothing. And actually now I am writing this I think I actually prefer this to having AutoMapper case sensitive. thanks Ray – RBrowning99 Dec 20 '13 at 01:24

2 Answers2

2

You can Refer :

DataReaderMapper should create case-insensitive mappings by default

http://automapper.codeplex.com/workitem/6127

you can control this in Mapper.Initialize as the answer AutoMapper: Mapping between a IDataReader and DTO object

another good post with examples on naming convention mappings: http://blog.ac-graphic.net/automapping-c-objects-from-one-naming-convention-to-an-other/

Community
  • 1
  • 1
Imran Ali Khan
  • 8,469
  • 16
  • 52
  • 77
0

The closes thing I could find is the the naming convention configurations: https://github.com/AutoMapper/AutoMapper/wiki/Configuration#naming-conventions

At the Profile or Mapper level you can specify the source and destination naming conventions:

Mapper.Initialize(cfg => {
  cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
  cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
});

Or:

public class OrganizationProfile : Profile 
{
  public OrganizationProfile() 
  {
    SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
    DestinationMemberNamingConvention = new PascalCaseNamingConvention();
    //Put your CreateMap... Etc.. here
  }
}
shenku
  • 11,969
  • 12
  • 64
  • 118