有没有人尝试过映射继承的属性?因为我很高兴听到它正常工作并且我在某处犯了错误,因为我收到以下错误:
"属性'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 { }
Run Code Online (Sandbox Code Playgroud)
我的AdvertisementConfiguration类看起来像这样:
class AdvertiserConfiguration : EntityTypeConfiguration<Advertiser>
{
public AdvertiserConfiguration()
{
// the following line indirectly causes an InvalidOperationException:
Property( x => x.UserName ).HasMaxLength(50);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我更改广告商类以使其不从User继承(并将UserName属性拉下来),那么一切正常.
entity-framework invalidoperationexception code-first entity-framework-4 ef-code-first
code-first ×1