views:

34

answers:

0

I have a problem when I try to map following class.

 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);
    }
}

Above code is work well, but when I uncomment "Pictures = new"... It throws this exception

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.

Dose one can tell me What is my wrong?
Is AutoMapper supported this class stucture?

Thank you.