Entity Framework - The foreign key component ... is not a declared property on type

c# entity-framework entity-framework-6

Question

I get this error:

The foreign key component 'SubdivisionHOAId' is not a declared property on type 'SubdivisionHOA'. Verify that it has not been explicitly excluded from the model and that it is a valid primitive property.

Here is my model. I don't understand what I need to do, as my understanding is that if I've specified [ForeignKey("SubdivisionsHOA")], it refers to my navigation property in the same class, so shouldn't it try to link on the 'Id' of SubdivisionHOA? I've been grappling with this for hours:

public partial class ContentArticleHOAsubdivision
{
    public int Id { get; set; }
    [ForeignKey("ContentArticleHOA")]
    public long ContentArticleId { get; set; }
    [ForeignKey("SubdivisionsHOA")]
    public short SubdivisionHOAId { get; set; }

    public virtual ContentArticleHOA ContentArticleHOA { get; set; }
    public virtual ICollection<SubdivisionHOA> SubdivisionsHOA { get; set; }
}

public partial class SubdivisionHOA
{
    [Key, ForeignKey("TopTierDivisionHOA")]
    public short Id { get; set; }
    public string Name { get; set; }

    public virtual TopTierDivisionHOA TopTierDivisionHOA { get; set; }
}
1
1
7/13/2014 8:35:27 AM

Popular Answer

Try this, add a property of the related entity type, in your case SubdivisionHOA, and add foreign key attribute to that property

public partial class ContentArticleHOAsubdivision
{

    public short SubdivisionHOAId { get; set; }

    [ForeignKey("SubdivisionsHOAId")]    
    public virtual SubdivisionHOA SubdivisionHOA {get;set;}

}
1
7/13/2014 9:01:34 AM


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