MVC 4 Code First ForeignKeyAttribute on property … on type … is not valid

前端 未结 1 1852
日久生厌
日久生厌 2020-12-19 16:28

I keep getting this error and I do not know why.

The ForeignKeyAttribute on property \'Ward\' on type \'BioSheet.Models.BioSheetModel\' is not valid. The foreign key

相关标签:
1条回答
  • 2020-12-19 17:25

    [ForeignKey("WardId")] indicates that the property to use as a foreign key to the Ward table should be the WardId property on the BioSheetModel class.

    You're getting the error because you haven't defined a WardId property on the BioSheetModel class.

    Add

    public int WardId {get; set;}
    

    for a non-nullable/required relationship, or

    public int? WardId {get; set;}
    

    for a nullable/optional relationship.

    0 讨论(0)
提交回复
热议问题