Entity Framework Code First Model Creation

Tom Chizek
12 min readSep 10, 2020
Tinpixels

Introduction

I have touched on this subject a few times but haven’t dug into it in any detail. In this article, I am going to use my Star Chart project to go into some additional depth with creating a real-world .Net Core Entity Framework Model. To be clear, this is a project that is in progress, so parts of what I will be showing today will probably look familiar if you have read any of my previous articles. However, the Database Context and Entity Framework Model that I am offering is current as of the writing of this piece. It is somewhat optimized — in that, for my local server testing, it is fast enough that I don’t go nuts working with it. It supports standard database CRUD operations (Create, Update, Delete, for non-database language speakers) via a set of .Net Core MVC classes handling the UI and middleware operations. I have tested this with both on-premise and Azure cloud database servers and configured the logging to feed Azure Application Insights giving a running trace for the state of the entire application.

The majority of this article will be focused on the DBContext classes OnModelCreating method because that is where the majority of the interesting activity happens. There are a few peripheral or setup activities that I will cover outside of the DBContext class because they relate to model creation. There are details…

--

--