Overview of Entity Framework Core - EF Core (2025)

  • Article

Entity Framework (EF) Core is a lightweight, extensible, open source and cross-platform version of the popular Entity Framework data access technology.

EF Core can serve as an object-relational mapper (O/RM), which:

  • Enables .NET developers to work with a database using .NET objects.
  • Eliminates the need for most of the data-access code that typically needs to be written.

EF Core supports many database engines, see Database Providers for details.

The model

With EF Core, data access is performed using a model. A model is made up of entity classes and a context object that represents a session with the database. The context object allows querying and saving data. For more information, see Creating a Model.

EF supports the following model development approaches:

  • Generate a model from an existing database.
  • Hand code a model to match the database.
  • Once a model is created, use EF Migrations to create a database from the model. Migrations allow evolving the database as the model changes.
using System.Collections.Generic;using Microsoft.EntityFrameworkCore;namespace Intro;public class BloggingContext : DbContext{ public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer( @"Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;ConnectRetryCount=0"); }}public class Blog{ public int BlogId { get; set; } public string Url { get; set; } public int Rating { get; set; } public List<Post> Posts { get; set; }}public class Post{ public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; }}

Querying

Instances of your entity classes are retrieved from the database using Language Integrated Query (LINQ). For more information, see Querying Data.

using (var db = new BloggingContext()){ var blogs = db.Blogs .Where(b => b.Rating > 3) .OrderBy(b => b.Url) .ToList();}

Saving data

Data is created, deleted, and modified in the database using instances of your entity classes. See Saving Data to learn more.

using (var db = new BloggingContext()){ var blog = new Blog { Url = "http://sample.com" }; db.Blogs.Add(blog); db.SaveChanges();}

EF O/RM considerations

While EF Core is good at abstracting many programming details, there are some best practices applicable to any O/RM that help to avoid common pitfalls in production apps:

  • Intermediate-level knowledge or higher of the underlying database server is essential to architect, debug, profile, and migrate data in high performance production apps. For example, knowledge of primary and foreign keys, constraints, indexes, normalization, DML and DDL statements, data types, profiling, etc.
  • Functional and integration testing: It's important to replicate the production environment as closely as possible to:
    • Find issues in the app that only show up when using a specific versions or edition of the database server.
    • Catch breaking changes when upgrading EF Core and other dependencies. For example, adding or upgrading frameworks like ASP.NET Core, OData, or AutoMapper. These dependencies can affect EF Core in unexpected ways.
  • Performance and stress testing with representative loads. The naïve usage of some features doesn't scale well. For example, multiple collections Includes, heavy use of lazy loading, conditional queries on non-indexed columns, massive updates and inserts with store-generated values, lack of concurrency handling, large models, inadequate cache policy.
  • Security review: For example, handling of connection strings and other secrets, database permissions for non-deployment operation, input validation for raw SQL, encryption for sensitive data.
  • Make sure logging and diagnostics are sufficient and usable. For example, appropriate logging configuration, query tags, and Application Insights.
  • Error recovery. Prepare contingencies for common failure scenarios such as version rollback, fallback servers, scale-out and load balancing, DoS mitigation, and data backups.
  • Application deployment and migration. Plan out how migrations are going to be applied during deployment; doing it at application start can suffer from concurrency issues and requires higher permissions than necessary for normal operation. Use staging to facilitate recovery from fatal errors during migration. For more information, see Applying Migrations.
  • Detailed examination and testing of generated migrations. Migrations should be thoroughly tested before being applied to production data. The shape of the schema and the column types cannot be easily changed once the tables contain production data. For example, on SQL Server, nvarchar(max) and decimal(18, 2) are rarely the best types for columns mapped to string and decimal properties, but those are the defaults that EF uses because it doesn't have knowledge of your specific scenario.

Next steps

For introductory tutorials, see Getting Started with Entity Framework Core.

Overview of Entity Framework Core - EF Core (2025)

FAQs

What is the overview of Entity Framework? ›

The Entity Framework enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern themselves with the underlying database tables and columns where this data is stored.

What is the Entity Framework Core? ›

Entity Framework Core (EF Core) is an open-source object-relational mapping (ORM) framework developed by Microsoft. It is a lightweight and cross-platform version of Entity Framework (EF). EF Core is designed to work with . NET Core and . NET 5 and later, making it more versatile and suitable for modern applications.

What are the differences between EF Core and Entity Framework? ›

Entity Framework (EF) refers to the older versions designed for the . NET Framework. Entity Framework Core (EF Core) is the modern, cross-platform ORM specifically designed for . NET Core and later versions.

What is Entity Framework for dummies? ›

Entity Framework is an ORM framework that allows developers to work with a relational database (SQL Server, Oracle, MySQL) in an object-oriented fashion. In Entity Framework, you write queries using LINQ, then retrieve or manipulate data as strongly typed objects using C# or VB.Net language.

What are the primary functions of the Entity Framework? ›

The following are the primary functions of EF:
  • It helps map domain classes to the database schema translates.
  • It keeps tracks of changes in the entities.
  • It helps execute LINQ queries to SQL.
  • It stores the changes stats to the database.

Why should I use Entity Framework Core? ›

EF should be considered a great ORM framework which allows faster development, easier and quicker operations to the DB, as long as you are careful and know how it works in order to avoid certain mistakes and create performance problems.

Is Entity Framework Core still used? ›

Entity Framework Core 5.0 (EF Core 5) was released for production use on 9 November 2020. It was retired and out of support 1.5 years later on May 10, 2022. Entity Framework Core 6.0 (EF Core 6) was released on 10 November 2021 and will be the preferred long-term supported version until at least 12 November 2024.

What is Entity Framework core first approach? ›

Using the Code First approach in EF Core
  1. Step 1: Define your domain classes. Start by creating the domain classes that correspond to the entities in your application. ...
  2. Step 2: Create the DbContext class. ...
  3. Step 3: Configure the DbContext. ...
  4. Step 4: Register the DbContext. ...
  5. Step 5: Migrate the database.
Jan 25, 2024

What is the EF core structure? ›

An EF Core model is a conceptual model of an application's domain. The domain includes all topics relevant to the problem-solving areas of interest to the application users. The model includes data and can also include behavior. Typically, models for CRUD applications don't tend to incorporate a lot of behavior.

What has replaced the Entity Framework? ›

Best Paid & Free Alternatives to Entity Framework Core
  • DbVisualizer.
  • Laravel.
  • Liquibase.
  • DBmaestro DevOps Platform.
  • SQL Toolbelt Essentials.
  • Pachyderm.
  • Cloud 66.
  • Toad DevOps Toolkit.

How does EF Core track entities? ›

Tracking from queries

EF Core change tracking works best when the same DbContext instance is used to both query for entities and update them by calling SaveChanges. This is because EF Core automatically tracks the state of queried entities and then detects any changes made to these entities when SaveChanges is called.

What is Entity Framework in simple words? ›

Entity Framework (EF) is an object-relational mapper that enables . NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write. Get it: Add this to your project and start taking advantage of this powerful O/RM.

What is everything about Entity Framework Core? ›

Example of Using Entity Framework Core ORM

The purpose is to enable developers to work with the data stored in databases in an object-oriented way. To achieve that, EF Core ORM provides a map between the objects defined in the application domain and the data stored in the database.

What is the context of Entity Framework? ›

Entity Framework Core is an open-source, popular, lightweight, and flexible cross-platform ORM. In Entity Framework Core (also called EF Core), a Db context is an object that coordinates queries, updates, and deletes against your database. It takes care of performing CRUD operations against your database.

What is the use of Entity Framework in? ›

Entity Framework works efficiently with widely used databases like SQL Server, SQL Server Compact, SQLite, PostgreSQL, Azure Table Storage, and IBM Data Server. Entity Framework makes it easier for programmers to perform create, read, update and delete (CRUD) operations by supporting databases.

What is entity overview? ›

About the entity overview

The entity overview provides a 360 view with easy access to information about where and how an entity is used: See where a product (any kind of entity) is active or not active in a Channel node.

What does Entity Framework include do? ›

Entity Framework Classic Include

The Include method lets you add related entities to the query result. In EF Classic, the Include method no longer returns an IQueryable but instead an IncludeDbQuery that allows you to chain multiple related objects to the query result by using the AlsoInclude and ThenInclude methods.

What is the overview of entity relationship diagram? ›

What is an ER diagram? An Entity Relationship (ER) Diagram is a type of flowchart that illustrates how “entities” such as people, objects or concepts relate to each other within a system.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 6027

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.