saturobi360 saturobi360 - 7 months ago 39
C# Question

Error when trying to create a Controller for web api

I keep getting this error, as showing in the screenshot below when I try adding a controller.
Any help in regards to resolving this error will be greatly appreciated.


The error stated that those entities (e.g. Firearm, FirearmDescription) have no key defined.

I can see you defined itemID. However, by convention this will not be used as the primary key unless you either

  1. Rename the field to FirearmId or,

  2. Add a [Key] attribute as below:

    public int itemID {get; set;}

You may learn more about the convention here: