2010-07-23 2 views
0

인사말 전문가Automapper : 조건부 유형을 어떻게 매핑합니까?

그래서 기본적으로 TripFeeSchedule에 사용하기 위해 설정 한지도가 있는데, 여행 요금 일정은 IEnumerable 유형입니다. 나는 5 가지 정도의 ValueResolvers를 가질 필요가 없기 때문에 이것을 매핑하려고 노력 중이다.

내가 기본적으로 원하는 것은 단일 수수료 일정에서 OPtional 수수료 유형을 매핑하는 것입니다. 예를 들어 유형이 연체료 인 경우 가격 및 수수료를 검색하여 적절하게 표시하는 특정 유형을 매핑하려고합니다. 이러한 수수료가 항상 존재하지는 않기 때문에 가능한 한 간단하게하려고합니다.

Mapper.CreateMap<Trip, TripManagementViewModelCreateEdit>().ForMember(dto => dto.TripOverride, opt => opt.ResolveUsing<TripCompResolver>().FromMember(x => x.TripComp)) 
.ForMember(dto => dto.BusOverride, opt => opt.ResolveUsing<TripCompResolver>().FromMember(x => x.TransportComp)).ForMember(dto => dto.RentalSki, opt => opt.MapFrom<TripFeeSchedule>(x=> x.ScheduledFees.First())); 

ScheduledFees이 나 사망, Refrenced하지 개체 말한다.

나는지도를 가지고 있으며

(디버거가 호출되고 있음을 보여줍니다) 작동하는 것 같군 [NullReferenceException이 :. 개체 참조가 개체의 인스턴스로 설정되지 않았습니다] AutoMapper.Mappers.PropertyMapMappingStrategy.MapPropertyValue을 (ResolutionContext 상황, IMappingEngineRunner 매퍼, mappedObject, PropertyMap propertyMap 개체) 393 AutoMapper.Mappers.PropertyMapMappingStrategy.Map (ResolutionContext 컨텍스트, IMappingEngineRunner 매퍼) 309 AutoMapper.Mappers.TypeMapMapper.Map (ResolutionContext 컨텍스트, IMappingEngineRunner 매퍼) 221 AutoMapper .MappingEngine.AutoMapper.IMappingEngineRunner.Map (ResolutionContext context)

[AutoMapperMappingException: Trying to map FreeLivinEnertainment.Core.TripFeeSchedule to FreeLivinEnertainment.Core.ViewModels.OptionalFee. 
Using mapping configuration for FreeLivinEnertainment.Core.TripFeeSchedule to FreeLivinEnertainment.Core.ViewModels.OptionalFee 
Destination property: RentalSki 
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.] 
    AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) +811 
    AutoMapper.Mappers.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap) +601 

[AutoMapperMappingException: Trying to map FreeLivinEnertainment.Core.TripFeeSchedule to FreeLivinEnertainment.Core.ViewModels.OptionalFee. 
Using mapping configuration for FreeLivinEnertainment.Core.TripFeeSchedule to FreeLivinEnertainment.Core.ViewModels.OptionalFee 
Destination property: RentalSki 
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.] 
    AutoMapper.Mappers.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap) +699 
    AutoMapper.Mappers.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper) +309 
    AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper) +221 
    AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) +723 

[AutoMapperMappingException: Trying to map FreeLivinEnertainment.Core.Trip to FreeLivinEnertainment.Core.ViewModels.TripManagementViewModelCreateEdit. 
Using mapping configuration for FreeLivinEnertainment.Core.Trip to FreeLivinEnertainment.Core.ViewModels.TripManagementViewModelCreateEdit 
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.] 
    AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) +811 
    AutoMapper.MappingEngine.Map(Object source, Type sourceType, Type destinationType) +132 
    AutoMapper.MappingEngine.Map(TSource source) +150 
    AutoMapper.Mapper.Map(TSource source) +117 
    FreeLivinEnertainment.Web.Controllers.Admin.TripsController.ShowEditTrip(Int32 id) in D:\Projects\jimbo\app\FreeLivinEnertainment.Web.Controllers\Controllers\Admin\TripManagementController.cs:138 
    lambda_method(ExecutionScope , ControllerBase , Object[]) +79 
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24 
    System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +52 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254 
    System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254 
    System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +192 
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +314 
    System.Web.Mvc.Controller.ExecuteCore() +105 
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39 
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7 
    System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34 
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8679150 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 

답변

0

723 나는 내가 단지 회원 가입일에서 람다를 실행할 수 있습니다 생각하고 내가 다시 결과를 얻을 필요가 무엇을 할 수, 바보 같은 느낌이 작업을 수행하는 방법을 알아 냈어.

opt => opt.ResolveUsing().FromMember(x => x.ScheduledFees.First()

관련 문제