升级到 EF6 后 - 该属性无法配置为导航属性 [英] After upgrade to EF6 - The property cannot be configured as a navigation property
问题描述
我有以下课程:
[Table("TagSource")]
public class TagSource
{
public TagSource()
{
this.DataSources = new HashSet<DataSource>();
}
[Key]
public int TagSourceId { get; set; }
...
public bool IsHistorical { get; set; }
public Nullable<int> ModifiedEntryId { get; set; }
...
public int? AttachedTagSourceId { get; set; }
[ForeignKey("AttachedTagSourceId"), InverseProperty("TagSourceId")]
public virtual TagSource AttachedTagSource { get; set; }
[ForeignKey("ModifiedEntryId"), InverseProperty("TagSourceId")]
public virtual TagSource ModifiedEntry { get; set; }
}
我使用的是 Entity Framework 5,但现在我已经(通过使用 nuget)升级到最新版本 - 6,之后我遇到了一个错误:
I was using Entity Framework 5, but now I have upraged (by using nuget) to newest version - 6, after doing that I'm encountering an error:
属性 'TagSourceId' 不能配置为导航属性.该属性必须是有效的实体类型,并且该属性应具有非抽象的 getter 和 setter.对于集合属性,该类型必须实现 ICollection,其中 T 是有效的实体类型.","ExceptionType":"System.InvalidOperationException"
"The property 'TagSourceId' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid entity type.","ExceptionType":"System.InvalidOperationException"
我已阅读该主题,但我没有像描述的那样参考:EF5 到 EF6 升级 - 导航属性已损坏
I have read that topic, but i have no references like described: EF5 to EF6 upgrade - navigation properties are broken
推荐答案
我也遇到了同样的问题.我删除了 InverseProperty
属性,问题就解决了.希望对您有所帮助.
I had the same problem. I removed InverseProperty
attributes and the problem solved. Hope it helps.
这篇关于升级到 EF6 后 - 该属性无法配置为导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!