自动映射例外:不支持的映射或缺少映射

时间:2013-11-25 19:36:10

标签: automapper

我看不出这两个映射函数的区别在于一个明显使用Automapper而另一个是手动卡塞。此映射不起作用:

   Mapper.CreateMap<AfterArrivalViewModel, UpdateAfterArrivalRequestDao>()
            .AfterMap((src, dest) =>
                       {
                           dest.TableId = Mapper.Map(src, new TableId());
                           dest.Identity = Mapper.Map(src, new Identity());
                           dest.ConditionExistPriorToTransfer = Mapper.Map(src, new ConditionExistPriorToTransfer());
                           dest.DependentMedicalOrSpecialEducationNeed = Mapper.Map(src, new DependentMedicalOrSpecialEducationNeed());
                           dest.IssueCategory = Mapper.Map(src, new IssueCategory());
                           dest.IssueCategory2 = Mapper.Map(src, new IssueCategory2());
                           dest.IssueCategoryDetails = Mapper.Map(src, new IssueCategoryDetails());
                           dest.IssueCategory2Details = Mapper.Map(src, new IssueCategory2Details());
                           dest.Reason = Mapper.Map(src, new ReasonExplanation());
                           dest.EmailAddress = Mapper.Map(src, new CommandPointOfContactEmailAddress());
                           dest.FirstName = Mapper.Map(src, new CommandPointOfContactFirstName());
                           dest.LastName = Mapper.Map(src, new CommandPointOfContactLastName());
                           dest.Commercial = Mapper.Map(src, new CommandPointOfContactPhoneCommercial());
                           dest.Dsn = Mapper.Map(src, new CommandPointOfContactPhoneDsn());
                           dest.Rank = Mapper.Map(src, new CommandPointOfContactRank());
                           dest.PlainLanguageAddress = Mapper.Map(src, new CommandPointOfContactPlainLanguageAddress());
                           dest.ProjectedRotationDate = Mapper.Map(src, new ProjectedRotationDate());
                           dest.MedicalDentalEducationalAnswer = Mapper.Map(src, new MedicalDentalEducationalAnswer());
                           dest.MedicalDentalEducationalExplaination = Mapper.Map(src, new MedicalDentalEducationalExplaination());
                           dest.UicAndNameOfMedicalFacility = Mapper.Map(src, new UicAndNameOfMedicalFacility());
                           dest.LastModifiedBy = Mapper.Map(src, new LastModifiedBy());
                       })
                       //.AfterMap((src, dest) => dest.InstantiateListOfSqlParameters())
                       ;

我最初将它作为之前的地图,但也没有用。

此映射确实有效:

   private IQueryCreationDao AssembleAfterArrivalDao(AfterArrivalViewModel model)
    {
        return new UpdateAfterArrivalRequestDao
        {
            TableId = Mapper.Map(model, new TableId()),
            Identity = Mapper.Map(model, new Identity()),
            ConditionExistPriorToTransfer = Mapper.Map(model, new ConditionExistPriorToTransfer()),
            DependentMedicalOrSpecialEducationNeed = Mapper.Map(model, new DependentMedicalOrSpecialEducationNeed()),
            IssueCategory = Mapper.Map(model, new IssueCategory()),
            IssueCategory2 = Mapper.Map(model, new IssueCategory2()),
            IssueCategoryDetails = Mapper.Map(model, new IssueCategoryDetails()),
            IssueCategory2Details = Mapper.Map(model, new IssueCategory2Details()),
            Reason = Mapper.Map(model, new ReasonExplanation()),
            EmailAddress = Mapper.Map(model, new CommandPointOfContactEmailAddress()),
            FirstName = Mapper.Map(model, new CommandPointOfContactFirstName()),
            LastName = Mapper.Map(model, new CommandPointOfContactLastName()),
            Commercial = Mapper.Map(model, new CommandPointOfContactPhoneCommercial()),
            Dsn = Mapper.Map(model, new CommandPointOfContactPhoneDsn()),
            Rank = Mapper.Map(model, new CommandPointOfContactRank()),
            PlainLanguageAddress = Mapper.Map(model, new CommandPointOfContactPlainLanguageAddress()),
            ProjectedRotationDate = Mapper.Map(model, new ProjectedRotationDate()),
            MedicalDentalEducationalAnswer = Mapper.Map(model, new MedicalDentalEducationalAnswer()),
            MedicalDentalEducationalExplaination = Mapper.Map(model, new MedicalDentalEducationalExplaination()),
            UicAndNameOfMedicalFacility = Mapper.Map(model, new UicAndNameOfMedicalFacility()),
            LastModifiedBy = Mapper.Map(model, new LastModifiedBy()),
        }
        ;
    }

除了一个是私有方法而另一个是自动播放器地图,我无法理解为什么当我打电话

  Mapper.Map<AfterArrivalViewModel, UpdateAfterArrivalRequestDao>(model);

我得到一个自动播放器异常,但是如果我调用该方法就可以了。

对此的任何帮助都会很棒!!

0 个答案:

没有答案