After upgrade to EF6 - The property cannot be conf

2019-04-12 13:36发布

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条回答
爷的心禁止访问
2楼-- · 2019-04-12 14:05

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

查看更多
登录 后发表回答