AutoMapper"未找到会员"使用UseDestinationValue

时间:2014-10-12 13:05:32

标签: c# entity-framework automapper-3

我正在尝试使用AutoMapper将ViewModel映射到模型。

这是我简化的ViewModel(源代码)类:

    public class EditPaypointVM
    {

        public Int64 Id { get; set; }

        public Int64 OrganisationId { get; set; }

        [Required]
        public string OrganisationContactNumber { get; set; }

        public Int64 PostalAddressId { get; set; }

        public string PostalAddressAddressText { get; set; }

        [Required]
        public Int64 PostalAddressArea { get; set; }

        public string PostalAddressAreaText { get; set; }

        public string PostalAddressCode { get; set; } 

        public Int64 PhysicalAddressId { get; set; }

        public string PhysicalAddressAddressText { get; set; }

        [Required]
        public Int64 PhysicalAddressArea { get; set; }

        public string PhysicalAddressAreaText { get; set; }

        public string PhysicalAddressCode { get; set; }
    }

这是我的简化模型(目标)类:

    public class Paypoint
    {
        public Int64 Id { get; set; }

        public virtual Organisation Organisation { get; set; }

        public virtual Employer Employer { get; set; }

        public virtual List<EmploymentContract> EmploymentContracts { get; set; }

        public bool IsActive { get; set; }
    }


    public class Organisation
    {
        public Int64 Id { get; set; }

        public virtual List<EmailAddress> EmailAdresses { get; set; }

        public virtual List<ContactNumber> ContactNumbers { get; set; }

        public virtual List<Address> Adresses { get; set; }

        public string RegisteredName { get; set; }

        public string TradingName { get; set; }

        public string RegistrationNumber { get; set; }

        public string WebsiteAddress { get; set; }
    }

以下是我在应用程序启动时在内存中创建映射的代码:

        Mapper.CreateMap<EditPaypointVM, Paypoint>()
           .ForMember(dest => dest.IsActive,
                opt => opt.UseValue(true))
           .ForMember(dest => dest.Organisation,
                opt => opt.UseDestinationValue())
           .Ignore(i => i.Employer)
           .Ignore(i => i.EmploymentContracts);

在单元测试中执行'AssertConfigurationIsvalid'时,会抛出“未映射的错误,该错误表明Paypoint的组织成员未映射。

关于导致这种情况的任何想法?

0 个答案:

没有答案