【发布时间】:2016-02-24 19:44:20
【问题描述】:
我试过这个问题:How to expose Foreign Key property to existing entity having navigational property using EF6 Code First,但它不起作用。我收到以下错误:
The index 'IX_FormEntry_Id' is dependent on column 'FormEntry_Id'.
ALTER TABLE ALTER COLUMN FormEntry_Id failed because one or more objects
access this column.
我只是想在 FormReport POCO 上公开 FormEntryId:
public class FormReport : Entity
{
public Guid? FormEntryId { get; set; } //I added this
public virtual FormEntry FormEntry { get; set; }
//other props
}
我使用了上面链接答案中概述的这个映射:
public class FormReportMapping : EntityTypeConfiguration<FormReport>
{
public FormReportMapping()
{
HasRequired(x => x.FormEntry)
.WithOptional()
.Map(p => p.MapKey("FormEntry_Id"));
new EntityMap().MapInheritedProperties(this);
}
}
我希望它能够识别,嘿,事情就是这样,不需要改变,但这不是正在发生的事情,我该怎么做?
编辑:我想保留我的命名约定,这与 EF 自动生成的不匹配。在我的 POCO 中,没有一个其他 FK 属性使用下划线。但这就是数据库中的列名。
【问题讨论】:
标签: c# .net entity-framework ef-code-first