Answer the question
In order to leave comments, you need to log in
How to get rid of the error "No parameterless constructor defined for this object." when using automapper?
I add in services in this way:
I tried it this way: I
get an errorservices.AddAutoMapper(typeof(Startup).Assembly);
services.AddAutoMapper();
"No parameterless constructor defined for this object."
public class DomainToDto: Profile
{
public DomainToDto()
{
CreateMap<A, ADto>();
CreateMap<List<A>, List<ADto>>();
CreateMap<B, BDto>();
CreateMap<List<B>, List<BDto>>();
}
}
public class B
{
[Required]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
public List<С> С { get; set; }
public List<D> D { get; set; }
[Required]
public int AId { get; set; }
public A A { get; set; }
public B(): base() { }
}
public class A
{
[Required]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
public List<B> B { get; set; }
public List<E> E { get; set; }
public A(): base() { }
}
public class BDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<string> CId { get; set; }
public List<string> DId { get; set; }
public int AId { get; set; }
public BDto(): base() { }
}
public class ADto
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public ADto(): base() { }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question