Becoming a software developer – episode XXII

Becoming a software developer – episode XXII

Welcome to the twenty-second episode of my course “Becoming a software developer” in which we will use SQL Server database along with Entity Framework Core library.

All of the materials including videos and sample projects can be downloaded from here.
The source code repository is being hosted on GitHub.



  • SQL Server
  • Entity Framework Core


SQL Server

At first, we need to have access to the SQL Server where we could store our data. You can download SQL Server here and install it on your own or just connect to the instance running somewhere in the cloud or locally by using Docker like I did.

Once the SQL Server is installed, there are many tools that provide a graphical interface for managing the database.
One of the most popular ones (and also free) is SSMS, yet there are also others such Datagrip, Team SQL or SQL Toolbelt. You can also use the mssql plugin for the Visual Studio Code.

Finally, execute the following script to create a new database and a table for the User type.

Entity Framework Core

Entity Framework Core is a new version of EF ORM (Object-relational mapping) designed to provide an access to the SQL Server database. It’s one of the most popular libraries for storing and retrieving the data from the SQL Server, as well as configuring the classes and the mappings between our models and database tables. Once we install the required dependencies, we can create a new DbContext which will be responsible for handling the connection:

Now, we can implement the UserRepository:

And finally, include the required services within Startup class:

The proper connection string using some default credentials may look like this: Server=localhost;User Id=SA;Password=abcd1234;Database=Passenger.


In the next episode, we will focus on publishing and deploy our application using tools such as Docker, Nginx and uploading it to the cloud where we will run a virtual machine containing Ubuntu Server.

13 Comments Becoming a software developer – episode XXII

  1. Mark

    Can you do an tutorial about automating publishing applications to windows server (IIS) with automated tests ? And can you recommend something like but up to 10-20 $ a month for closed source projects ? (or even better for free )

    1. Piotr Gankiewicz

      Hey, please take a look at my previous posts. I did a tutorial about Travis CI, BitBucket Pipelines (that’s a great alternative) and others. I’m not using IIS unfortunately, but it should be pretty much the same scenario as publishing the application to the Ubuntu Servers, especially if you use Docker.

  2. Pingback: Dew Drop - July 17, 2017 (#2521) - Morning Dew

        1. Piotr Gankiewicz

          Raczej na pewno nie, przynajmniej nie w najbliższej przyszłości. Praktycznie nie używam już baz SQL, do tych zagadnień jest masa przykładów w sieci, a poza tym i tak nie użyłbym aktualnej wersji EF Core produkcyjnie.

  3. Łukasz

    Why create repository? This is abstraction over abstraction. Why not use the EF in the services directly? What is the point?
    Second question. This is a thing that I have seen many times. Returning the entire record (entity) from the database. Retrieving record using this repository for the User, it gets all the fields from database. What if e. eg. we want only user id and name for drop down list? We can have 20+ fields in the table, but only need two for this specific user case. So what to do? Get all of them this is a waste of resources. Moreover this is a simple SELECT * FROM … This is not how databases should be quering.
    Using the repository pattern I was created specific methods for specific queries with custom DTOs, but this is a garbage in the repository. Even creating them as a extension methods. So I’m not sold for this pattern. But still looking for a hints from others that may have different different points of view.

    1. Piotr Gankiewicz

      Thanks for pointing this out, I’m aware of all of these things, but in case you have not noticed, this was a basic video about SQL Server + EF, not an in-depth tutorial lasting a few hours. Besides that topic, DbContext is a repository and UOW itself, but due to its poor design is not an interface, thus injecting a class directly into application services makes them impossible to test. I’m not a fan of EF and not a fan of using a repository with DbContext either, however, if you look at the repository like at some generic interface, you’re missing the whole point of the domain.

  4. Arek

    W jaki sposób do projektu byś zaczął implementować frontend np. Angular4 od strony architektury ? Nowy projekt typu Passager.WebSite czy w samym Api i komunikacja między 2 stronami? Mógłbyś troszkę nakierować jak by można to prawidłowo wykonać ?

      1. Arek

        Może moje pytanie śmiesznie zabrzmi ale czy na produkcji nie wzrośnie delay pomiędzy odpowiedziami API do Website ? (Wszystko by było na 1 serwerze)


Leave A Comment

Your email address will not be published. Required fields are marked *