I'm using the AutoMapper library to map my ViewModels.
I have my DBdomain class:
public class DBDominio
{
[Key]
[Column("ID")]
public long id { get; set; }
[Required]
[StringLength(128)]
[Column("ID_USU")]
public string idUsu { get; set; }
[Required]
[StringLength (200)]
[Column("URL")]
public string url { get; set; }
[StringLength (100)]
[Column("ID_c")]
public string idC { get; set; }
[StringLength(100)]
[Column("ID_s")]
public string idS { get; set; }
}
And my viewModel VMDomainDetails:
public class VMDominioDetails
{
public long id { get; set; }
public string idUsu { get; set; }
public string url { get; set; }
public string idC { get; set; }
public string idS { get; set; }
}
In my Global.asax I added the AutoMapperWebConfiguration.Configure ();
My configuration class looks like this:
AutoMapperWebConfiguration
public static class AutoMapperWebConfiguration
{
public static void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile(new DominioProfile());
});
Mapper.AssertConfigurationIsValid();
}
}
And my DomainProfile class:
public class DominioProfile : Profile
{
protected override void Configure()
{
Mapper.CreateMap<DBDominio, VMDominioDetails>();
}
}
When trying to "map", I get the following error:
Missing type mapping or unsupported mapping.
Mapping types: DBDomain - > VMDomainDetails PROJECT.Models.DBModels.DBDomain - > PROJECT.Models.ViewModels.VMDomainDetails
Destination path: VMDomainDetails
Source value: PROJETO.Models.DBModels.DBDomain
Description: An unhandled exception occurred during the execution of the current Web request. Examine the stack trace for more information about the error and where it originated in the code.
Exception Details: AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types: DBDomain - > VMDomainDetails PROJECT.Models.DBModels.DBDomain - > PROJECT.Models.ViewModels.VMDomainDetails
Destination path: VMDomainDetails
Source value: PROJETO.Models.DBModels.DBDomain
The error happens on this line, where dBDominio
is an object of type DBDominio
VMDominioDetails d = new VMDominioDetails();
d = _map.Map<VMDominioDetails>(dBDominio);
I have tried to use a reverse reference in the configuration to see if it would solve, thus: Mapper.CreateMap<DBDominio, VMDominioDetails>().ReverseMap()
, but not resolved.