0
다음 클래스를 매핑하려고 할 때 문제가 있습니다. 코드 위AutoMapper는 복합 클래스 구조를 지원합니까?
class LazyStudent : ActiveRecordBase
{
[Property]
public String Name
{
set;
get;
}
[HasMany(typeof(LazyStudentBook))]
public IList<LazyStudentBook> Books
{
set;
get;
}
}
class LazyStudentBook : ActiveRecordBase
{
[Property]
public String BookName
{
set;
get;
}
[HasMany(typeof(LazyStudentBookPicture))]
public IList<LazyStudentBookPicture> Pictures
{
set;
get;
}
[BelongsTo]
public LazyStudent LazyStudent
{
set;
get;
}
}
class LazyStudentBookPicture : ActiveRecordBase
{
[Property]
public String PictureName
{
set;
get;
}
[Property]
public LazyStudentBook LazyStudentBook
{
set;
get;
}
}
class Student
{
public String Name
{
set;
get;
}
public IList<StudentBook> Books
{
set;
get;
}
}
class StudentBook
{
public String BookName
{
set;
get;
}
public IList<StudentBookPicture> Pictures
{
set;
get;
}
}
class StudentBookPicture
{
public String PictureName
{
set;
get;
}
}
class TestAutoMapper
{
public static void Start()
{
Mapper.CreateMap<LazyStudent, Student>();
Mapper.CreateMap<LazyStudentBook, StudentBook>();
Mapper.CreateMap<LazyStudentBookPicture, StudentBookPicture>();
Mapper.CreateMap<IList<LazyStudent>, IList<LazyStudent>>();
Mapper.CreateMap<IList<LazyStudentBookPicture>, IList<StudentBookPicture>>();
IList<LazyStudent> lazyStudents = new List<LazyStudent>
{
new LazyStudent{
Name = "AAA",
Books = new List<LazyStudentBook>{
new LazyStudentBook{
BookName = "BookName"
/*,
Pictures = new List<LazyStudentBookPicture>{
new LazyStudentBookPicture{
PictureName = "PictureName"
}, new LazyStudentBookPicture{
PictureName = "PictureName"
}
}*/
}
}
}
};
IList<Student> sList = Mapper.Map<IList<LazyStudent>, IList<Student>>(lazyStudents);
}
}
는 잘 작동하지만, 내가 주석을 해제 할 때 "사진 = 새로운"... 그것은이 예외 일 내 잘못은 무엇 말해 줄 수
Trying to map System.Collections.Generic.IList`1[[TestAOP.LazyStudent, Test.Com.Ko.Aop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] to System.Collections.Generic.IList`1[[TestAOP.Student, Test.Com.Ko.Aop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
용량을 던져?
AutoMapper가이 클래스 구조를 지원합니까?
감사합니다.
을 수행 할 수 있습니다/questions/2645293/automapper-to-ienumerable에 실패 함 – wearetherock