Emit Mapper IList Mapping

Dec 22, 2011 at 4:50 AM
Edited Dec 22, 2011 at 4:52 AM

Hello, I have 2 model classes for my view as below:

 

    public class UserModel
    {
        public virtual int ID { get; set; }       
        public virtual string LoginName { get; set; }
        public virtual string Password { get; set; }
        public virtual IList<QuestionModel> AskedByMeQuestions { get; set; }
        public virtual IList<QuestionModel> AssignedToMeQuestions { get; set; }
    }

    public class QuestionModel
    {
        public virtual int ID { get; set; }
        public virtual UserModel AskedBy{ get; set; }
        public virtual string Title{ get; set; }
        public virtual UserModel AssignedTo{ get; set; }
       }

 

Also, 2 entity class for the db tables with NHibernate mapping purpose:

 

    public class User
    {
        public virtual int ID { get; set; }       
        public virtual string LoginName { get; set; }
        public virtual string Password { get; set; }
        public virtual IList<QuestionModel> AskedByMeQuestions { get; set; }
        public virtual IList<QuestionModel> AssignedToMeQuestions { get; set; }
    }

    public class Question
    {
        public virtual int ID { get; set; }
        public virtual UserModel AskedBy{ get; set; }
        public virtual string Title{ get; set; }
        public virtual UserModel AssignedTo{ get; set; }
      }

 

The things when i tried to map user from db retrieve to user model using following statements, it will throw an exception -- " Constructor for types [] not found in System.Collections.Generic.IList`1[[MobileHospital.Web.Models.QuestionModel, MobileHospital.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]", which proves that the IList field is failed in mapping:

 

User user = userDAL.FindByName(Name);
UserModel um = ObjectMapperManager.DefaultInstance.GetMapper<User, UserModel>().Map(user);

 

Could someone see into whats wrong with it, i cant find  a clue from the wiki or google. its quite like the issue described in http://stackoverflow.com/questions/5834574/emitmappers-list-mapping-issue-with-collections.

 

Thanks very much!

May 17, 2012 at 5:12 PM

Hi

I'm experiencing the same problem with generic collections.

Any help for this?

May 17, 2012 at 11:42 PM

Hi, after trying sorts of solutions, i gave up and turned to use automapper instead.

May 17, 2012 at 11:43 PM
cobain81 wrote:

Hi

I'm experiencing the same problem with generic collections.

Any help for this?

 

Hi, after trying sorts of solutions, i gave up and turned to use automapper instead.

Mar 13, 2014 at 1:46 PM
It should work if you'd substitute IList<QuestionModel> to QuestionModel[] in destination model.