Net основное приложение. Я пытаюсь использовать Auto mapper, но это приводит к ошибке ниже.
.Net Core Automapper missing type map configuration or unsupported mapping
У меня есть настройки ниже в startup.cs
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new MappingProfile());
});
IMapper mapper = mappingConfig.CreateMapper();
services.AddSingleton(mapper);
Затем я использую профили.
public class MappingProfile : Profile
{
public MappingProfile()
{
this.CreateMap<Geography, GeographyEntity>();
this.CreateMap<Model1, Model2>();
}
}
Я использую автоматический сопоставитель, как показано ниже
Model1 model = this.Mapper.Map<Model1>(Model2);
Ниже приведены модели
public partial class Model1
{
public int SNo { get; set; }
public string SarNo { get; set; }
public string SiteName { get; set; }
public string Client { get; set; }
public int CId { get; set; }
public DateTime StartDate { get; set; }
public bool IsActive { get; set; }
public virtual Model2 C { get; set; }
}
public class Model2
{
public int SNo { get; set; }
public string SarNo { get; set; }
public string SiteName { get; set; }
public int CId { get; set; }
public string Client { get; set; }
public bool? IsActive { get; set; }
public DateTime StartDate { get; set; }
}
Я получаю ошибку ниже в автоматическом сопоставлении.
AutoMapper.AutoMapperMappingException: Отсутствует конфигурация карты типов или неподдерживаемое сопоставление.
Может ли кто-нибудь помочь мне разобраться в этой ошибке? Любая помощь будет принята с благодарностью. Спасибо