EF Weirdness - invalid column of XXXXX
Some days there is just weirdness that makes no sense.
My error message was "invalid column of StoreMenuId". The error message did not make any sense. I had no column called that in any table or view in my database.
Also wrong was when I looked at the properties on the table after I eventually found them in a weird place under EntityType in Intellisense. I had all the correct columns PLUS this mysterious column.
Once I finally saw this, I knew the problem. Turns out the real problem was I had not attributed a foreign key properly in the model. The mysterious foreign key was named StoreMenuId.
Was:
public int UpdateId { get; set; }
Should be:
[ForeignKey("StoreMenu")]
public int UpdateId { get; set; }
public StoreMenu? StoreMenu { get; set; }
The UpdateId is a foreign key that should match up against "StoreMenu.Id" column. I guess the error message stripped the period for some reason.
Comments
Post a Comment