2010-07-09 3 views
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가이 클래스 구조를 지원합니까?

감사합니다.

+1

나중에 참조 할 수 있도록

을 수행 할 수 있습니다/questions/2645293/automapper-to-ienumerable에 실패 함 – wearetherock

답변

0

즉, 목록을 목록에 매핑하는 AutoMapper에 말할 필요가 없습니다. 상관하지 않습니다. 유형을 매핑하는 방법에 대해 설명하십시오.

Nm 당신은 그것을 생각했습니다. 사용자가 생성 한 후 내가 대답이 스레드 http://stackoverflow.com에서 "당신은 명시 적으로 수집 유형 만 항목 유형을 매핑 할 필요가 없습니다"를 가지고

AutoMapper.AssertConfigurationIsValid(); 
관련 문제