Answer the question
In order to leave comments, you need to log in
How can I convert nested object in Automapper?
Good evening! I have two classes that are connected in a many-to-many relationship. The structure is like this:
class A
{
public class A
{
public Guid Id { get; set; }
public List<AB> AB { get; set; }
}
public class B
{
public Guid Id { get; set; }
public List<AB> AB { get; set; }
}
public class AB
{
public Guid AId { get; set; }
public Guid BId { get; set; }
public A A { get; set; }
public B B { get; set; }
public string Status { get; set; }
}
public class ADto
{
public Guid Id { get; set; }
public List<BDto> B { get; set; }
public string Status { get; set; }
}
public class BDto
{
public Guid Id { get; set; }
public List<ADto> A { get; set; }
public string Status { get; set; }
}
}
Answer the question
In order to leave comments, you need to log in
No way, stop using the automapper for other purposes, in ForMember you can not use custom scripts, code, or properties of the second nesting level, as well as LINQ expressions containing code. You can write your own custom mapping, but it will not support compile-time optimization, that is, it will be executed at runtime like regular code, and there will be no advantages over regular code, that is, besides this, the readability of such code will be below the plinth.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question