我有两个类,一个是由实体框架生成的,另一个是我到处使用的类。
我的课 :
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
EF类:
public class PERSON
{
public string FIRST_NAME { get; set; }
public string LAST_NAME { get; set; }
}
当源为PERSON
to时我找到了解决方案Person
,但我没有找到 to 的解决方案Person
(PERSON
属性为大写和下划线分隔符)。
The solution for PERSON to Person :
Mapper.Initialize(x => x.AddProfile<Profile1>());
var res = Mapper.Map<PERSON, Person>(person);
public class UpperUnderscoreNamingConvention : INamingConvention
{
private readonly Regex _splittingExpression = new Regex(@"[p{Lu}0-9]+(?=_?)");
public Regex SplittingExpression
{
get { return _splittingExpression; }
}
public string SeparatorCharacter
{
get { return "_"; }
}
}
public class Profile1 : Profile
{
protected override void Configure()
{
SourceMemberNamingConvention = new UpperUnderscoreNamingConvention();
DestinationMemberNamingConvention = new PascalCaseNamingConvention();
CreateMap<PERSON, Person>();
}
}