saturobi360
saturobi360

Reputation: 13

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

Upvotes: 0

Views: 86

Answers (1)

Alex Lau
Alex Lau

Reputation: 1697

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

Upvotes: 1

Related Questions