私は次のクラスを持っています:
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; }
}
そして、この構造に関連付けられたテーブル "Publications" には、これらすべてのフィールド (ProductContact のプロパティを含む) があります。
(ProductContact 情報を含む) Publication 行を挿入しようとすると、プログラムは例外をスローします。
System.NotSupportedException: The member Contact of type ProductContact cannot be used as a parameter value
そこで、ProductContact プロパティを Properties テーブルのフィールドにマップするマッパーを追加しました。
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();
}
このマッパーを使用すると、同じ例外が発生します。
次に、Contact フィールドの ignore ステートメントを追加して、Dapper にこの要素を挿入ステートメントに含めないように指示しました。
Map(x => x.Contact).Ignore();
この場合、別の例外が発生します。
System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@FullName".
これは、Dapper がこのプロパティを完全に無視していることを示しており、前の手順で追加されたマッピングは効果がありません。
ProductContact プロパティをテーブル フィールドにマッピングする方法はありますか?
ありがとうございました。