Date
オブジェクトをラップしDateTime
て Date 部分のみを公開するカスタムクラスがあります。
エンティティに含めようとしていますが、例外が発生します:
error 3004: Problem in mapping fragments starting at line 6:No
mapping specified for properties Goal.Date in Set Goal.\r\nAn Entity with Key
(PK) will not round-trip when:\r\n Entity is type [EFCodeFirstSandbox.Goal]
何を与える?カスタム クラスを EF の世界でうまく機能させるにはどうすればよいですか?
以下は、カスタムDate
クラスの単純化されたバージョンです。
public class Date
{
private DateTime value;
public Date(DateTime date)
{
this.value = date.Date;
}
public static implicit operator Date(DateTime date)
{
return new Date(date);
}
public static implicit operator DateTime(Date date)
{
return date.value;
}
}
を使用するエンティティ クラスDate
:
public class Goal
{
[Key]
public Guid Id { get; set; }
public Date Date { get; set; }
public int Amount { get; set; }
}
編集: このDate
クラスは、説明目的でのみ使用されます。SQL で日付を表す方法ではなく、POCO 以外のカスタム クラスをマップする方法に興味があります。:)