A Few MVC SQL Tips and Tricks

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.

  1. 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)]
    auto_increment
  2. Here is a handy snippet you need to add to Global.asax in order to add more than one controller to your project:
    Database.SetInitializer<YourProjectContext>(new DropCreateDatabaseIfModelChanges<YourProjectContext>());
    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.
    if_model_changes

On the Second Week of Code Bootcamp

So, I just completed my second week of immersive full-time code study at We Can {Code} IT. I feel bad for people who have to go work a day job and/or have kids to take care of after school, because I sure don’t have any energy left! Who knew that sitting in a classroom could tire you out so much?

Anyway, I am proud to say that so far I’m keeping up with class. We have been studying all the fundamentals of C# (or basically any other object oriented programming language): loops, arrays, if-then statements, strings, etc.

Having spent a year trying to teach this to myself put me in a good starting position but my “I already get this” moments are just about done. Starting today (that is, this weekend) we were informed that we had better buckle down because it is going to ramp up in difficulty next week.

I’m excited and scared, because I still have issues with my understanding of some of the basics. Well, I understand them, but I still make mistakes with picking the correct loop type to use and placing my statements in the right order to get the result I am after. I am not the quickest in the class, and seeing other people have lightbulb moments before I do is something I am having to deal with. I wish I were 20 years younger!

But things are great so far! I have never had a bad day yet. I’ve had bad moments, but not a whole bad day. Can’t wait for Monday!

When I can’t stand to look at a screen any longer I draw.
Here, have a silver laced Wyandotte.

chicken