I have the following classes:
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; }
}
And the table associated with this structure, "Publications", has all these fields (included the properties of ProductContact).
If I try to insert a Publication row (with the ProductContact information included) the program throws an exception:
System.NotSupportedException: The member Contact of type ProductContact cannot be used as a parameter value
So, I added a mapper to map out the ProductContact properties to fields in the Properties table:
public PublicationMapper ()
{
TableName = "Publications";
Map(x => x.Contact.FullName).Column("ContactFullName");
Map(x => x.Contact.JobTitle).Column("ContactJobTitle");
Map(x => x.Contact.Email).Column("ContactEmail");
AutoMap();
}
With this mapper I get the same exception.
Then, I added the ignore statement for the Contact field, to tell Dapper to not include this element in the insert statement
Map(x => x.Contact).Ignore();
In this case, I get another exception:
System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@FullName".
It indicates that Dapper is ignoring completely this property, and the mapping added in the previous step does not have effect.
Is there a way to map out the ProductContact properties to the table fields?
Thank you.