有没有人尝试过映射继承的属性?因为我很高兴听到它有效并且我在某处犯了错误,因为我收到以下错误:
“属性 '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);
}
}
如果我更改 Advertiser 类使其不从 User 继承(并拉下 UserName 属性),那么一切正常。