Tengo una cadena que es una fecha válida pero es una cadena y debe ser una cadena. Sin embargo cuando intento mapa de auto a una fecha y hora que se produce una excepción¿Cómo asignar una cadena a una fecha en Automapper?
Trying to map System.String to System.DateTime.
Trying to map System.String to System.DateTime.
Using mapping configuration for ViewModels.FormViewModel to Framework.Domain.Test
Destination property: DueDate
Missing type map configuration or unsupported mapping.
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: AutoMapper.AutoMapperMappingException: Trying to map System.String to System.DateTime.
Using mapping configuration for ViewModels.FormViewModel to
Framework.Domain.Task
Destination property: DueDate
Missing type map configuration or unsupported mapping.
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
yo habría esperado que lo haría un convertido automático pero supongo que tengo que decir que de alguna forma para hacer esto.
¿Cómo puedo decir que convierta?
Terminé haciendo algo así, aunque utilicé una resolución. No sabía que tenían un convertidor. No hago tantos controles como tú, ya que sentí que era mi validación para hacer eso. – chobo2
Si usa un convertidor, maneja todas las conversiones de cadena-> fecha, en cualquier lugar. Pensé en incluir uno, pero hay mucho de qué preocuparse con la localización, etc. La mayoría de las veces uso: CreateMap(). ConvertUsing (Convert.ToDateTime); –
@Jimmy Bogard - ¿Por qué CreateMap(). ForMember (d => d, opt => opt.MapFrom (DateTime.Parse)); ¿No funciona? –
Rookian