In my last post I discussed plans for a personal budgeting web app using asp.net core along with other newer technologies. Good news - I haven’t given up yet! Although I may intermingle non-series posts in between these to break up the monotony.
We start our project by building the data model and database. I decided to give Entity Framework Core a go, using Code First to build the model and database in one-fell-swoop. Despite the pain I hear associated with Code First, it seems to be a non-issue if you aren’t on a large team of folks all touching the model classes.
Since I’m all on my own here, let’s go with it.
To get up to speed, I watched Julie Lerman’s Getting Started With Entity Framework 6 course on Pluralsight. I also followed along the initial steps of Tom Dykstra’s Get started with ASP.NET Core and Entity Framework Core using Visual Studio tutorial. Both awesome, check em’ out.
Entity Framework Core is a bit different from the standard 6.x versions of Entity Framework so some of the info in Julie’s course can’t be used. For example, don’t try and use the Entity Framework Power Tools extension to visualize the database EF will create, it ain’t supported!
For this first part, I didn’t have to veer off much from the guidance of the tutorials. Here’s the steps I took:
Create a .NET Core Class Library project in Visual Studio 2015 to hold the models.
Add my model classes - if you recall in my last post I mentioned I’ll start off by building a simple personal finance app. Something just to record inflows and outflows against your standard checking, savings, and credit card accounts. I’ll add the budget related stuff later.
Create a second .NET Core Class Library that will be responsible for all the Entity Framework stuff.
DbContext, migrations, and any other data access code. Let’s keep it three-tier, shall we?
Create the DbContext-derived BudgetContext class with DbSets to inform Entity Framework to do it’s thing and create the database.
Create a .NET Core Web Application project using the Web API template. I wasn’t going to do this yet but in order to actually create the database you need to have a startup project with connection strings and a database provider. I tried 12 times to get my
Add-Migration InitialMigrationcommand to work! Ensuring my Web App project had a reference to the project holding the DbContext, adding a parameterless constructor, and referencing the EntityFrameworkCore.Tools package where all necessary for my initial DB creation by Entity Framework.
That’s it so far. I pushed the project to github so y’all can follow along. And as always, if you liked this, please share the URL to your various social networks, and join my newsletter below to stay current! My ideal is that I can post something useful and interesting for the .NET community every week.
P.S. I think I should have comments on here but I think Disqus is ugly. I want something more minimal…