Skip to content

11. Entity Framework

Whenever you need to handle databases in the .net world you should go for the Entitiy Framework, it is Microsofts ORM (Object Relational Mapper) and more, it supports

  • database first (start with your existing database)
  • code first (start with your classes etc, use this, whenever you can)

EF Core is the part that runs on all platforms. EF supports many DBMS, see Database Providers.

Follow the instructions of Getting Started with EF Core and create your first console application using EF.

orm
Entity Framework[^1]

Read the chapter 6. Entity Framework with SQL Server1.

A database is just another source for LINQ, hence it is very easy to query databases, see LINQ Queries.

As you might have learned in HCI in mobile applications the repository pattern is widely used. Read Building an App with Repositories and Document DB2 how to implement the repository pattern for .Net applications and how to test them.


  1. Jason Hales, Almantas Karpavicius, and Mateus Viegas. The C# workshop: Kickstart your career as a software developer with C#. Packt Publishing, Birmingham, UK, [first edition] edition, 2022. ISBN 9781800566491. URL: https://learning.oreilly.com/library/view/the-c-workshop/9781800566491/

  2. Adam Tibi. Pragmatic Test-Driven Development in C and .NET: Write loosely coupled, documented, and high-quality code with DDD using familiar tools and libraries. Packt Publishing Limited, Birmingham, 1 edition, 2022. ISBN 9781803231303. URL: https://learning.oreilly.com/library/view/pragmatic-test-driven-development/9781803230191/B18370_09.xhtml#_idParaDest-218