Dapper Extension: class with composite fields, mapped to an individual table
<p>I have the following classes: </p>

<pre><code>public class Publication
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Headline { get; set; }
    public DateTime Published { get; set; }
    public ProductContact Contact { get; set; }
}

public class ProductContact
{
    public string FullName { get; set; }
    public string JobTitle { get; set; }
    public string Email { get; set; }
}
</code></pre>

<p>And the table associated with this structure, "Publications", has all these fields (included the properties of ProductContact). </p>

<p>If I try to insert a Publication row (with the ProductContact information included) the program throws an exception:</p>

<pre><code>System.NotSupportedException: The member Contact of type ProductContact cannot be used as a parameter value
</code></pre>

<p>So, I added a mapper to map out the ProductContact properties to fields in the Properties table:</p>

<pre><code>  public PublicationMapper ()
    {
        TableName = "Publications";

        Map(x =&gt; x.Contact.FullName).Column("ContactFullName");
        Map(x =&gt; x.Contact.JobTitle).Column("ContactJobTitle");
        Map(x =&gt; x.Contact.Email).Column("ContactEmail");

        AutoMap();
    }
</code></pre>

<p>With this mapper I get the same exception.</p>

<p>Then, I added the ignore statement for the Contact field, to tell Dapper to not include this element in the insert statement</p>

<pre><code>            Map(x =&gt; x.Contact).Ignore();
</code></pre>

<p>In this case, I get another exception:</p>

<pre><code>System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@FullName".
</code></pre>

<p>It indicates that Dapper is ignoring completely this property, and the mapping added in the previous step does not have effect.</p>

<p>Is there a way to map out the ProductContact properties to the table fields?</p>

<p>Thank you.</p>