EF Code First - Invalid column name

前端 未结 1 661
有刺的猬
有刺的猬 2021-01-11 17:13

Im getting an error \"Invalid column name \'FeeLevel_LevelId\' which makes absolutely no sense considering all properties are simple types and there is no FeeLevel nor a Lev

相关标签:
1条回答
  • 2021-01-11 17:20

    FeeLevel.MemberFeeDiscountLevels is a navigation property and it introduces a one-to-many relationship between FeeLevel and MemberFeeDiscountLevel: A FeeLevel can have many MemberFeeDiscountLevels which means at the same time that a MemberFeeDiscountLevel has a single FeeLevel. Although you don't have a navigation and foreign key property in MemberFeeDiscountLevel the database must have a foreign key in the MemberFeeDiscountLevel table in order to model this relationship. EF assumes a default FK name as "related entity name+underscore+primary key name" = FeeLevel_LevelId. Because your database table doesn't have this column you get the exception.

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