I have 3 levels of nesting in my project. Something like that:
public class Assignment
{
public Element Element { get; set; }
}
public class Element
{
public Subject Subject { get; set; }
}
public class Subject
{
public int? Id { get; set; }
public string Subject_Title { get; set; }
}
Each class has many other properties. The database follows the same structure. Now I want to map assignmentfrom the database to view the model.
The mapping I wrote with help automapperworks for the first time, but not after. Thus, the value Subjectis null in subsequent runs, and the Element value in all runs. The problem is only with the topic.
Can someone point me in the right direction and tell me what I'm doing wrong?
Mapper.CreateMap<db_Subject, Subject>();
Mapper.CreateMap<db_element, Element>()
.ForMember(dest => dest.Subject, opt => opt.MapFrom(src => src.db_Subject));
Mapper.CreateMap<db_assignment, Assignment>()
.ForMember(dest => dest.Element, opt => opt.MapFrom(src => src.db_element));
, db_subject db_element, db_element db_assignment. .