After upgrade to EF6 - The property cannot be configured as a navigation property

牧云@^-^@ 提交于 2019-12-09 19:25:55

问题


I have a following class:

[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; }
}

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:

"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"

I have read that topic, but i have no references like described: EF5 to EF6 upgrade - navigation properties are broken


回答1:


I had the same problem. I removed InverseProperty attributes and the problem solved. Hope it helps.



来源:https://stackoverflow.com/questions/23334685/after-upgrade-to-ef6-the-property-cannot-be-configured-as-a-navigation-propert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!