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.

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.

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:

dotnet new console -n EntityFrameworkCoreExample
Installing EF Core and Package References

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

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; }
}








