継承されたプロパティをマッピングしようとした人はいますか?次のエラーが発生するので、それがうまく機能し、どこかで間違いを犯していると聞いてうれしいからです。
「プロパティ'UserName'は、タイプ'Advertiser'で宣言されたプロパティではありません。IgnoreメソッドまたはNotMappedAttributeデータアノテーションを使用して、プロパティがモデルから明示的に除外されていないことを確認してください。有効なプリミティブプロパティであることを確認してください。」
私のモデルは次のようになります。
abstract class Entity { public int Id {get; set; }}
abstract class User : Entity { public string UserName {get; set;} }
sealed class Advertiser : User { }
私のAdvertisementConfigurationクラスは次のようになります。
class AdvertiserConfiguration : EntityTypeConfiguration<Advertiser>
{
public AdvertiserConfiguration()
{
// the following line indirectly causes an InvalidOperationException:
Property( x => x.UserName ).HasMaxLength(50);
}
}
Userから継承しないように(そしてUserNameプロパティをプルダウンするように)Advertiserクラスを変更すると、すべてが正常に機能します。