EF Code first invalid column name “CategoryCategoryID”

后端 未结 1 1202
北恋
北恋 2021-01-01 23:53

There is a existing database named Northwind with a webform application. when running the application raise up a error: \'invalid column name CategoryCategoryID\'. any one h

1条回答
  •  醉梦人生
    2021-01-02 00:17

    One way to solve this is to add a new FK property to your Product entity:

    public class Product
    {
        public int ProductID { get; set; }        
        public string ProductName { get; set; }
        public Decimal? UnitPrice { get; set; }
        public bool Discontinued { get; set; }
        [ForeignKey("Category")]
        public int CategoryId { get; set; }
    
        public virtual Category Category { get; set; }
    }
    

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