Note that there are some explanatory texts on larger screens.

plurals
  1. POEmitMapper's List Mapping Issue with Collections
    primarykey
    data
    text
    <p>The source class:</p> <pre><code>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&lt;Category&gt; Categories { get; set; } public virtual List&lt;Comment&gt; Comments { get; set; } public virtual List&lt;Tag&gt; Tags { get; set; } } </code></pre> <p>the destination class</p> <pre><code>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&lt;Category&gt; Category { get; set; } public List&lt;Comment&gt; Comments { get; set; } public List&lt;Tag&gt; Tags { get; set; } } </code></pre> <p>I try using EmitMapper to map from each other; when mapping from source to desction, here is the code sample:</p> <pre><code>[TestMethod] public void ShouleMapEntityToModel() { Post eP = new Post(); eP.ID = 2; eP.Comments = new List&lt;Comment&gt;(); eP.Comments.Add(new Comment() { ID = 2, Author = "derek" }); var mP = eP.Map&lt;Post, mBlog.Core.Models.Post&gt;(); Assert.IsNotNull(mP); Assert.AreEqual(1, mP.Comments.Count()); } </code></pre> <p>and I got an exception,</p> <p>Test method mBlog.Test.EmitMapperTest.ShouleMapEntityToModel threw exception: System.Exception: Constructor for types [] not found in System.Collections.Generic.IList`1[[mBlog.Core.Models.Post, mBlog.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload