Created
October 22, 2016 16:24
-
-
Save kleberksms/53477d865e238c6476f7e7a1247cc60f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Models | |
public class Comarca | |
{ | |
public Comarca(){} | |
public Comarca(string descricao, Guid ufId) | |
{ | |
Id = Guid.NewGuid(); | |
Descricao = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(descricao); | |
UfId = ufId; | |
} | |
public Guid Id { get; private set; } | |
public virtual Uf Uf { get; set; } | |
public string Descricao { get; private set; } | |
public Guid UfId { get; private set; } | |
} | |
public class Uf | |
{ | |
public Uf(){} | |
public Uf(string descricao, string sigla) | |
{ | |
Descricao = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(descricao); | |
Sigla = CultureInfo.CurrentCulture.TextInfo.ToUpper(sigla); | |
Id =Guid.NewGuid(); | |
} | |
public Guid Id { get; private set; } | |
public string Descricao { get; private set; } | |
public string Sigla { get; private set; } | |
public virtual ICollection<Comarca> Comarcas { get; set; } | |
} | |
//DTOs | |
public class ListagemComarcaViewModel | |
{ | |
public Guid Id { get; set; } | |
public string Descricao { get; set; } | |
} | |
public class ListagemUfViewModel | |
{ | |
public Guid Id { get; set; } | |
public string Descricao { get; set; } | |
public string Sigla { get; set; } | |
public List<ListagemComarcaViewModel> Comarcas { get; set; } | |
} | |
//Mapeamento | |
public IEnumerable<ListagemUfViewModel> RetonaListaViewModelUfComarca(List<Uf> list) | |
{ | |
try | |
{ | |
Mapper.Initialize( | |
cfg => cfg.CreateMap<Comarca, ListagemComarcaViewModel>() | |
.ForMember(dest => dest.Descricao, t => t.MapFrom(s => s.Descricao)) | |
.ForMember(dest => dest.Id, t => t.MapFrom(s => s.Id)) | |
); | |
Mapper.Initialize(cfg => cfg.CreateMap<Uf, ListagemUfViewModel>() | |
.ForMember(dest => dest.Comarcas, t => t.MapFrom(s => | |
Mapper.Map<List<Comarca>,List<ListagemComarcaViewModel>>(s.Comarcas.ToList()) | |
)) | |
.ForMember(dest => dest.Descricao, t => t.MapFrom(s => s.Descricao)) | |
.ForMember(dest => dest.Sigla, t => t.MapFrom(s => s.Sigla)) | |
.ForMember(dest => dest.Id, t => t.MapFrom(s => s.Id)) | |
); | |
var result = Mapper.Map<List<Uf>, List<ListagemUfViewModel>>(list); | |
Mapper.AssertConfigurationIsValid(); | |
return result; | |
} | |
catch (AutoMapperConfigurationException exception) | |
{ | |
throw new Exception(exception.ToString()); | |
} | |
catch (AutoMapperMappingException exception) | |
{ | |
throw new Exception(exception.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AutoMapper.AutoMapperMappingException: Error mapping types.
Mapping types:
List
1 -> List
1System.Collections.Generic.List
1[[BPTrack.Models.Localidade.Uf, BPTrack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.List
1[[BPTrack.ViewModel.ListagemConfiguracaoViewModel.ListagemUfViewModel, BPTrack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] ---> AutoMapper.AutoMapperMappingException: Error mapping types.Mapping types:
Uf -> ListagemUfViewModel
BPTrack.Models.Localidade.Uf -> BPTrack.ViewModel.ListagemConfiguracaoViewModel.ListagemUfViewModel
Type Map configuration:
Uf -> ListagemUfViewModel
BPTrack.Models.Localidade.Uf -> BPTrack.ViewModel.ListagemConfiguracaoViewModel.ListagemUfViewModel
Property:
Comarcas ---> AutoMapper.AutoMapperMappingException: Error mapping types.
Mapping types:
List
1 -> List
1System.Collections.Generic.List
1[[BPTrack.Models.Localidade.Comarca, BPTrack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.List
1[[BPTrack.ViewModel.ListagemConfiguracaoViewModel.ListagemComarcaViewModel, BPTrack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] ---> AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.Mapping types:
Comarca -> ListagemComarcaViewModel
BPTrack.Models.Localidade.Comarca -> BPTrack.ViewModel.ListagemConfiguracaoViewModel.ListagemComarcaViewModel
em lambda_method(Closure , Comarca , ListagemComarcaViewModel , ResolutionContext )
em AutoMapper.ResolutionContext.Map[TSource,TDestination](TSource source, TDestination destination)
em lambda_method(Closure , List
1 , List
1 , ResolutionContext )--- Fim do rastreamento de pilha de exceções internas ---
em lambda_method(Closure , List
1 , List
1 , ResolutionContext )em AutoMapper.Mapper.AutoMapper.IMapper.Map[TSource,TDestination](TSource source)
em AutoMapper.Mapper.Map[TSource,TDestination](TSource source)
em lambda_method(Closure , List
1 , List
1 , ResolutionContext )--- Fim do rastreamento de pilha de exceções internas ---
em lambda_method(Closure , List
1 , List
1 , ResolutionContext )--- Fim do rastreamento de pilha de exceções internas ---
em lambda_method(Closure , List
1 , List
1 , ResolutionContext )em AutoMapper.Mapper.AutoMapper.IMapper.Map[TSource,TDestination](TSource source)
em AutoMapper.Mapper.Map[TSource,TDestination](TSource source)
em BPTrack.Application.ConfiguracaoLogistica.ConfiguracaoLogisticaApplication.RetonaListaViewModelUfComarca(List`1 list) na C:\Users\Kleber\Documents\Visual Studio 2015\Projects\BPTrack\BPTrack\Application\ConfiguracaoLogistica\ConfiguracaoLogisticaApplication.cs:linha 101