saturobi360 saturobi360 - 2 months ago 10
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.

http://i693.photobucket.com/albums/vv293/saturobi360/Error/API_error_zpswocovwbw.jpg

Answer

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:

    [Key]
    public int itemID {get; set;}
    

You may learn more about the convention here: https://msdn.microsoft.com/en-us/data/jj591583.aspx#Key

Comments