Featured Article

C# Entity Framework Core Example: A Comprehensive Guide

Kenneth Jul 13, 2026

C# Entity Framework Core, often abbreviated as EF Core, is a popular ORM (Object-Relational Mapping) library developed by Microsoft. It's designed to work with .NET Core and enables developers to interact with databases using C# objects andوظ الموسم Lamar expressions, without having to write SQL queries. Here's a comprehensive guide with practical examples to help you get started.

Free Entity Framework Book
Free Entity Framework Book

EF Core supports multiple databases, including SQL Server, Oracle, MySQL, PostgreSQL, and SQLite. It provides features like lazy loading, config-driven data access, change tracking, and migrations. This article will focus on using EF Core for a simple console application with SQL Server.

#dotnet #entityframework #efcore #aspnetcore #backenddevelopment #softwareengineering #webdevelopment #programmingconcepts #techlearning #developercommunity | Sagar Saini
#dotnet #entityframework #efcore #aspnetcore #backenddevelopment #softwareengineering #webdevelopment #programmingconcepts #techlearning #developercommunity | Sagar Saini

Setting Up Your Project

First, let's set up a new .NET Core Console Application project using the global tool dotnet. Open your terminal or command prompt, then type the following command to create a new project:

Introduction to Entity Framework Core - The Engineering Projects
Introduction to Entity Framework Core - The Engineering Projects

dotnet new console -n EntityFrameworkCoreExample

Installing EF Core and Package References

C++20 / C++23 Range Views
C++20 / C++23 Range Views

The new project comes with a top-level .csproj file. Open it and add the following package references inside the :

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.6" /></ItemGroup>

These packages provide the necessary dependencies for using EF Core with SQL Server and for performing database migrations. You can remove other unnecessary packages like Microsoft.EntityFrameworkCore for this example.

Creating a Simple Model

Code First Approach in Entity Framework in Asp.net MVC with Example - Tutlane
Code First Approach in Entity Framework in Asp.net MVC with Example - Tutlane

EF Core uses POCO (Plain Old CLR Objects) entities to represent database tables. Let's create a simple entity called Blog with properties for Id, Url, and CreatedAt.

Create a new folder named Models, then add a new class file named Blog.cs with the following content:

public class Blog
{
    public int Id { get; set; }
    public string Url { get; set; }
    public DateTime CreatedAt { get; set; }
}

a computer screen with the words ccna and other information on it, including an image of
a computer screen with the words ccna and other information on it, including an image of
Saeed Esmaeelinejad on LinkedIn: #entityframeworkcore #ef #dotnet #csharp | 30 comments
Saeed Esmaeelinejad on LinkedIn: #entityframeworkcore #ef #dotnet #csharp | 30 comments
a notebook with the words c complete notes on it
a notebook with the words c complete notes on it
an image of a computer screen with the words conventional and central networked on it
an image of a computer screen with the words conventional and central networked on it
Entity-Relationship Diagram (ERD)
Entity-Relationship Diagram (ERD)
OSI Model Layers Explained | Networking Basics for Beginners
OSI Model Layers Explained | Networking Basics for Beginners
the concept framework for an instructional framework to teach how to use it in your classroom
the concept framework for an instructional framework to teach how to use it in your classroom
the ct image is shown in blue and white
the ct image is shown in blue and white
Coding - 🚀 30 Days CSS Series!  Day 16: Flex Container Properties #css #html | Facebook
Coding - 🚀 30 Days CSS Series! Day 16: Flex Container Properties #css #html | Facebook
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes