the source class:
public class post { public long id { get; set; } [column(typename="nvarchar")] [required] [stringlength(250)] public string name { get; set; } [column(typename="varchar")] [stringlength(250)] public string urlname { get; set; } [column(typename="ntext")] public string excerpt { get; set; } [column(typename="ntext")] [required] public string content { get; set; } public datetime postedtime { get; set; } public datetime? publishedtime { get; set; } public datetime? lastupdatedtime { get; set; } public bool ispublished { get; set; } public virtual list<category> categories { get; set; } public virtual list<comment> comments { get; set; } public virtual list<tag> tags { get; set; } }
the destination class
public class post : model { public long id { get; set; } public string name { get; set; } public string urlname { get; set; } public string excerpt { get; set; } public string content { get; set; } public datetime postedtime { get; set; } public datetime lastcommentedtime { get; set; } public bool ispublished { get; set; } public list<category> category { get; set; } public list<comment> comments { get; set; } public list<tag> tags { get; set; } }
i try using emitmapper map each other; when mapping source desction, here code sample:
[testmethod] public void shoulemapentitytomodel() { post ep = new post(); ep.id = 2; ep.comments = new list<comment>(); ep.comments.add(new comment() { id = 2, author = "derek" }); var mp = ep.map<post, mblog.core.models.post>(); assert.isnotnull(mp); assert.areequal(1, mp.comments.count()); }
and got exception,
test method mblog.test.emitmappertest.shoulemapentitytomodel threw exception: system.exception: constructor types [] not found in system.collections.generic.ilist`1[[mblog.core.models.post, mblog.core, version=1.0.0.0, culture=neutral, publickeytoken=null]]
i had same problem, have found solution. don't user lists destination object. if use simple arrays in mblog.core.models.post object should nicely filled object. destination class should like:
public class post : model { public long id { get; set; } public string name { get; set; } public string urlname { get; set; } public string excerpt { get; set; } public string content { get; set; } public datetime postedtime { get; set; } public datetime lastcommentedtime { get; set; } public bool ispublished { get; set; } public category[] category { get; set; } public comment[] comments { get; set; } public tag[] tags { get; set; } }
Comments
Post a Comment