2016-12-28 6 views
3

Это мой домен ТипC# AutoMapper, изменение Mapper Установка на лету

[Table("CredentialingCallDetail")] 
[BsonIgnoreExtraElements] 
public class CredentialingCallDetail : FullAuditedEntity<ObjectId> 
{ 
    public string RepresentativeName { get; set; } 
    public string PhoneNumber { get; set; } 
    public string PhoneExtension { get; set; } 
    public string CallResultStatus { get; set; } 
    public string IsFacilityCredentialed { get; set; } 
    public string Provider { get; set; } 
    public string PIN { get; set; } 
    public List<LicensedProfessionalCredentialed> LicensedProfessionalCredentials { get; set; } 
} 

Объект А это мой Передача данных Objet

[AutoMapTo(typeof(CredentialingCallDetail))] 
public class CreateCredentialingCallDetailInput 
{  
    [BsonIgnore] 
    public string Id { get; set; } 
    [Required] 
    public string RepresentativeName { get; set; } 
    [Required] 
    public string PhoneNumber { get; set; } 
    public string PhoneExtension { get; set; } 
    [Required] 
    public string CallResultStatus { get; set; } 
    public string IsFacilityCredentialed { get; set; } 
    public string Provider { get; set; } 
    public string PIN { get; set; } 
    public string Status { get; set; } 
    public List<LicensedProfessionalCredentialedDto> LicensedProfessionalCredentials { get; set; } 
    public CreateCredentialingCallDetailInput() 
    { 
     LicensedProfessionalCredentials = new List<LicensedProfessionalCredentialedDto>(); 
    } 
} 

Когда карта CreateCredentialingCallDetailInput к CredentialingCallDetail т.е.

CredentialingCallDetail newCredentialingCallDetail = input.CredentialingCallDetail.MapTo<CredentialingCallDetail>(); 

Я получаю исключение enter image description here

Существует несоответствие между типом идентификатора, Automapper не является строкой привязки к ObjectId, Is Is any way, я могу изменить настройку на лету, т. Е. Изменить параметр, чтобы игнорировать отображение идентификаторов?

+0

С новыми версиями AM вы можете создать несколько профилей отображения вместо статической одноплодной отображении он имел прежде. Просто создайте другой профиль и используйте в своем сопоставлении. –

ответ

2

Ответ можно найти в this вопрос (да вопрос!). Вы можете сделать это двумя способами. Проверьте вопрос для деталей.

Быстрый ответ для вас.

При определении сопоставления вы можете игнорировать дополнительные элементы.

CreateMap<CreateCredentialingCallDetailInput, CredentialingCallDetail >() 
.ForSourceMember(src => src.Id, opt => opt.Ignore()) 

Просто добавьте вторую строку к существующему картографированию.

Это выглядит неоднозначно,

CredentialingCallDetail newCredentialingCallDetail = 
input.CredentialingCallDetail.MapTo<CredentialingCallDetail>(); 

Если это не будет что-то вроде этого

CredentialingCallDetail newCredentialingCallDetail = 
CreateCredentialingCallDetailInput.MapTo<CredentialingCallDetail>();