Entity Framework: Code First

A few days ago we had our second user group meeting for 2016 at Cyprus .NET User Group and it was all about data access. I was the speaker at the event and I presented Entity Framework and more specifically the “Code First” development approach.


What is Entity Framework?

Entity Framework is an Object/Relational Mapping (ORM) Framework that treats data as Domain-Specific Objects. Entity Framework supports a variety of DBMSs.

The purpose of Entity framework is to simplify the data-access required when developing database applications.

In order to work with Entity Framework you need:

In order to install Entity Framework, right after you start a new project in Visual Studio, you can add it either via the GUI of NuGet Manager or via Package Manager Console with the command: Install-Package EntityFramework.

Entity Framework - Code First (Article on SQLNetHub)
Figure 1: NuGet Package Manager.


Entity Framework - Code First (Article on SQLNetHub)
Figure 2: Package Manager Console – Syntax for Installing Entity Framework.


What is Code First?

Code First was first introduced in Entity Framework 4.1 and it follows the Domain Driven Design (DDD) paradigm. It is one of the three available development approaches in Entity Framework. The main idea is to create Domain Classes based on which the database can be created in the background.

In Entity Framework you can query data with any of the below methods:

  • LINQ to Entities
    • Method syntax
    • Query syntax
  • Entity SQL
  • Native SQL


Entity Framework - Code First (Article on SQLNetHub)
Figure 3: Component Stack when Using Entity Framework. Source: MSDN.


Learn more about Entity Framework  – Enroll to our online course!

Enroll to our online course “Entity Framework: Getting Started – Complete Beginners Guide“, and learn all about Entity Framework, what it is, how it works, how to use it for data access when developing .NET apps, what are its available workflows and their pros and cons. Also, via comprehensive live demonstrations, we will build many apps using Visual Studio with C# and Entity Framework.

Entity Framework: Getting Started (Ultimate Beginners Guide) - Online course
(Lifetime Access / Downloadable Resources and more!)

Learn More


Watch video: What is Entity Framework and what are its Benefits?


Watch video: How to Create and Configure a Model in .NET Entity Framework Core Using Fluent API (Code First)


Watch video: Entity Framework: Getting Started – Complete Beginners Guide (Course Preview)


Featured Online Courses:


Check our other related Entity Framework and .NET articles:


Read also:


Check our latest software releases!

Easily generate SQL code snippets with Snippets Generator!

Convert static T-SQL to dynamic and vice versa with Dynamic SQL Generator.

Secure your SQL Server instances with DBA Security Advisor.


Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.75 out of 5)


Reference: SQLNetHub.com (https://www.sqlnethub.com)

© SQLNetHub