Thursday, January 12, 2017

My next steps - My own project and 100 Days of Code

I finished the book Head First C#. What is the next step? I don't want to lose any of the information I was supposed to have learned. I have another book "Beginning C# Object-Oriented Programming." I look at the book every now and again and think I should start reading it. I probably will very soon. But, I also started thinking that there is no better way then to program my own personal project to help me feel invested in the programming and gain a benefit for something that I want to do.

I was invested in learning while going through the book, but maybe not as invested as I could have been. I took time to take notes while reading and really tried to understand what the exercises were trying to teach. I may have not always had an idea of where, outside of the written steps, would I be able to use the code. My new idea, using what I learned to create my own project. And what better way to stay accountable then posting on twitter every day on the progress I am making than making a commitment with 100 days of code.

I would be more invested in my own project as it is my idea and I would really like to see it come to life. Over the years I have had many ideas that I wanted an app that filled a "need" (or at least a need for me). Some of the ideas have apps out there and sometimes I have downloaded them (such as when I wanted an app that not only kept recipes, but made a grocery list for me). Others I have just looked at and said, I might try to create my own. The first one I wanted to try is a movie database.

I have a lot of movies and can always go look at the movies, but sometimes I want to be lazy and just pull out my phone to see what movies I have. I decided to jump in. Right away I jumped in and thought I need to do an API. Day 1 on my Twitter feed: Starting the API. The API would allow me to either later create a web, desktop, or phone app. I got going. I was reading through tutorials and watching videos, I felt I was learning and even got an API to send data back (although hardcoded data).



Learning is good. However, as I kept going, I was missing something. The tutorial of creating the API came with the database already created and the interactions between the API and the database were already created. I learned this quickly. The video I was watching talked about the data context, at work my co-workers talked about context on the API we are building as well, but I wasn't sure how the context was created (or really how the context interacted where it needed).

Time to take a step back. What is the context and how does it talk to the database? Luckily, I was talking to my co-worker, Peter, and he mentioned that Entity Framework is what we used at work. Eureka! Entity framework is the first step I should take. I found a Pluralsight course on Entity Framework 6. And this helped! Making sure Entity Framework got the correct relationships in the database took me a while. I think what I was missing was that each of the classes had to refer to each other. My "MoviesOwned" class had to have an object for "MovieTitles" and "MovieTitles" had to know about "MoviesOwned." Once I added all these relationships Entity Framework recognized my relationships.

public class MoviesOwned
    {
        public List MovieTitles { get; set; }

        public int MovieTitlesId { get; set; }
     }
public class MovieTitles
    {
        public MoviesOwned Movie { get; set; }

        public int MoviesOwnedId { get; set; }
    }

I was able to see that the relationships were in my model I used a tool called Entity Framework Power Tools. However, I use Visual Studio 2015 and this didn't show up in my list of Extensions and Updates. However, Julie Lerman had a great blog post on how to fix this issue.

I know know the context is the database context. It has an object from each of the classes so it knows what needs to be created. Entity Framework is then able to see what database objects you want and looks at the class of each of those objects to determine the structure of the database.The key is to have your context class inherit from DbContext (I believe this comes from Entity Framework)




After deployment, I see my database in SQLExpress (I need to figure out how to not use Express so I can host the database somewhere else).

The question becomes, is the structure really correct? And will I be able to write code that will communicate with the database correctly?

You can see daily progress on Twitter, @robertjorg.
You can see my daily log (called log.md) uploaded to GitHub: https://github.com/robertjorg/100-days-of-code/
I am being transparent and posting my work to Github. Maybe someone will see issues I am coding and plus I am blogging about what I am doing anyway. That link is: https://github.com/robertjorg/MovieDatabase

I hope to blog more because I should be coding every day and it is something I am choosing the project so I hope to be more attached to the code.

"The length of a file should be directly related to the endurance of the human bladder."
-Alfred Hithcock