If I have a many-to-many relationship defined in EF:
public class StudentImage
{
public int StudentId { get; set; }
public int ImageId { get; set; }
public int Order { get; set; }
public virtual Student Student { get; set; }
public virtual Image Image { get; set; }
}
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<StudentImage> Images { get; set; }
}
public class Image
{
public int Id { get; set; }
public string Filename { get; set; }
public virtual ICollection<StudentImage> Students { get; set; }
}
And the DTO's:
public class ImageDTO
{
public int Id { get; set; }
public string Filename { get; set; }
public int Order { get; set; }
}
public class StudentIDO
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<ImageDTO> Images { get; set; }
}
How could I map from Student to StudentDTO and from Image to ImageDTO using Automapper?
So Image and ImageDTO is relationship 1:1.That's easy mapping by AutoMappper
Mapper.CreateMap(); The last Student and StudentDTO, they have include list.
Sometime if you try that it not good for performance. Thanks
Mappings
Usage