升级到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屋!