I have been working with Visual Studio 2015, MVC .NET and MS SQL lately, and ran into several things that I had to keep looking up over and over, so I thought there may be someone else out there in the same boat.
Note: These are all tips for working code-first in Visual Studio.
- In your Model, say you want to have a table’s Primary Key auto-increment. Sure you add [Key], but you also need to add this: [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
- Here is a handy snippet you need to add to Global.asax in order to add more than one controller to your project:
In my screenshot, the name of my project is IceCream. If you don’t know the name of your project context, it should just be the name of your project with “context” on the end. I know that’s pretty basic, but as a new coder, it sometimes throws me. Global.asax is located at the very bottom of your Solution Explorer.