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

asp.net-mvc-5 entity-framework entity-framework-6

Question

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
3
5/23/2017 12:28:35 PM

Popular Answer

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

1
9/3/2014 1:44:57 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow