I am first time user of Automapper using version 6.2.2. I am try to find out how can I map below DB entity to custom DTO.
public partial class vw_Owner
{
public int Space_Id { get; set; }
public string Owner_ID { get; set; }
public string Owner_SID { get; set; }
public string Owner_Name { get; set; }
}
public class OwnerDTO
{
public int SpaceId { get; set; }
public string OwnerID { get; set; }
public string OwnerSID { get; set; }
public string OwnerName { get; set; }
}
Below is my mapping profile.
public class MappingProfile : Profile
{
public static readonly IMapper iMapperConfig;
static MappingProfile()
{
var config = new MapperConfiguration(cfg =>
{
//cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
//cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
//cfg.AddMemberConfiguration().AddName<ReplaceName>(_ => _.AddReplace("_", ""));
cfg.CreateMap<vw_Owner, Owner>();
});
iMapperConfig = config.CreateMapper();
}
}
I also tried to create my own custom naming convention. Below is code, but it is not working.
public class UnderscoreNamingConvention : INamingConvention
{
public Regex SplittingExpression { get; } = new Regex(@"[\p{Lu}\p{Ll}0-9]+(?=_?)");
public string SeparatorCharacter => "_";
//public string ReplaceValue(Match match) => match.Value;//.ToLower();
public string ReplaceValue(Match match)
{
return match.Value;
}
}
I tried commented lines from documentation, but doesn't seems to work. I have 15+ similar database entities containing _ but DTO classes doesn't. I am looking for a way to fix for all entities with some resolver.
Thanks