System.Data.SqlClient.SqlException: Invalid column name 'phone_types_phone_type_id'

前端 未结 7 637
野的像风
野的像风 2020-12-10 02:28

I\'m trying to get information from some of my models that have a foreign key relationships to my main employee model. If I map out each model individually, I can access the

7条回答
  •  感动是毒
    2020-12-10 02:49

    You are right. I had similar issue. Something like this

       [ForeignKey("StatesTbl")]
       public int? State { get; set; }
       public StatesTbl StateTbl { get; set; }
    

    So as you can see, I had kept name 'StateTbl' in the last line instead of 'StatesTbl' and app kept looking for StateTblID. Then I had to change name to 'StatesTbl' instead. And then it started working well. So now, my changed lines were:

       [ForeignKey("StatesTbl")] <== 'StatesTbl' is my original States table
       public int? State { get; set; }
       public StatesTbl StatesTbl { get; set; }
    

    These are in the AppDbContext.cs class file

提交回复
热议问题