Entity Type Has No Key Defined

后端 未结 4 1384
走了就别回头了
走了就别回头了 2021-02-19 08:00

Another \'Entity Type \'x\' has no key defined\' question, but I\'ve set the [Key] attribute on a property so I\'m a bit confused.

Here\'s my entity and con

相关标签:
4条回答
  • 2021-02-19 08:42

    To help clarify, this line:

    public string GMCNumber;

    needs to become:

    public string GMCNumber { get; set; }

    0 讨论(0)
  • 2021-02-19 08:48

    You need to change GMCNumber to a property not a field.

    0 讨论(0)
  • 2021-02-19 08:53

    I ran into this post after facing a similar issue today. The problem was that I was attempting to create the scaffold after adding the [Key] attribute to my model and without compiling. Once I compiled with the [Key] attribute the scaffolding generated just fine.

    0 讨论(0)
  • 2021-02-19 08:55

    I encountered the same error message when I had defined the property as private.

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