.NET Framework .NET C# VB.NET LINQ ASP.NET Web API REST SignalR Windows Forms WPF WCF RabbitMQ PHP SQL Server MySQL PostgreSQL MariaDB SQLite MongoDB ADO.NET ORM Entity Framework Dapper XML JSON HTML5 CSS3 Bootstrap JavaScript jQuery Angular React TypeScript NPM Blazor UI/UX Responsive Web Design Redis Elasticsearch GraphQL Grafana Agile Scrum Kanban Windows Server IIS PowerShell Active Directory TFS Azure Automation Software Reverse Engineering Performance Optimization Git Jira/Confluence CI/CD TeamCity SOLID KISS DRY YAGNI
Always will be ready notify the world about expectations as easy as possible: job change page

Top 9 Entity Framework Core Features in 2023 you can’t miss

Добавлено: Oct 26, 2023
Автор: Alex Maher
Источник: источник
Просмотров: 148

Entity Framework Core Features in 2023

Entity Framework Core

EF Core 2023 has rolled out some pretty cool stuff, and I’m excited to share it with you. So, grab a cup of coffee, and let’s get started!

1. Cosmos DB Provider Improvements

Azure Cosmos DB and EF Core are like two peas in a pod, but with EF Core 8.0, they’re even cozier. Enhanced support means tighter integration and smoother operations.

Code Example:

var cosmosOptionsBuilder = new DbContextOptionsBuilder<MyContext>()
    .UseCosmos("", "myPrimaryKey", "myDatabaseName");

This is a significant leap for cloud developers. The tighter integration reduces boilerplate code, making our cloud-based apps more efficient and maintainable.

2. Temporal Tables

Time-travel isn’t just for sci-fi movies. With SQL Server temporal tables support, EF Core 8.0 lets us revisit our data’s past states.

Code Example:

modelBuilder.Entity<Order>().ToTable("Orders", t => t.IsTemporal());

This feature is a lifesaver for debugging and auditing. Being able to track data changes directly from EF Core simplifies many tasks that previously required complex solutions.

3. Table-per-Type (TPT) Mapping

Data modeling debates have a new contender. TPT mapping in EF Core 8.0 offers a fresh approach to organizing our data, especially when inheritance is in play.

Code Example:


For projects where data separation is crucial, TPT is a breath of fresh air. It provides clarity in the database schema, making it easier to manage and understand.

4. Migrations Bundles

Deployment headaches, be gone! Migrations Bundles in EF Core 8.0 encapsulate all migration-related elements, streamlining the deployment process.

Code Example:

var bundle = context.Database.CreateMigrationBundle();
File.WriteAllBytes("", bundle);

This is a game-changer for CI/CD pipelines. Simplifying migrations means fewer deployment issues and faster release cycles.

5. Compiled Models

Speed is the name of the game. With Compiled Models, EF Core 8.0 boosts startup performance, especially for models with a large number of entities.

Code Example:

var options = new DbContextOptionsBuilder<MyContext>()

In today’s fast-paced world, every millisecond counts. Improving startup times enhances user experience, especially in microservices architectures.

6. HierarchyID Mapping

Organizing data in a hierarchical manner has always been a challenge. With the introduction of hierarchyid type support in EF Core 8.0, representing data like organizational charts or file systems becomes more intuitive.

Code Example:

modelBuilder.Entity<Organization>().Property(e => e.HierarchyId).HasConversion<string>();

This feature simplifies the representation of tree structures in our databases. It’s a step forward in making complex data structures more manageable and queryable.

7. Raw SQL Queries for Unmapped Types

Sometimes, ORM can feel restrictive, especially when we need to execute raw SQL. EF Core 8.0 expands its raw SQL capabilities, allowing us to return any mappable CLR type, even if it’s not part of our EF model.

Code Example:

var blogs = context.Set<Blog>().FromSqlRaw("SELECT * FROM dbo.Blogs").ToList();

This feature provides the flexibility many developers crave. It bridges the gap between raw SQL and ORM, offering the best of both worlds.

8. Updating Hierarchies

Hierarchical data structures are common, but updating them? That’s a different ball game. EF Core 8.0 introduces mechanisms to update hierarchyid columns seamlessly, making changes to hierarchical data structures a breeze.

Code Example:

var node = new HierarchyNode("/1/3/");
node = node.GetReparentedValue(oldRoot: new HierarchyNode("/1/"), newRoot: new HierarchyNode("/2/"));

This feature is a testament to EF Core’s commitment to simplifying complex operations. Being able to reparent a node or a sub-hierarchy without manual SQL scripting is a huge time-saver.

9. Configuration of and Complex Types

With flexibility at its core, EF Core 8.0 offers multiple ways to configure complex types. Whether you prefer mapping attributes or love diving deep into the OnModelCreating method, EF Core has got you covered.

Code Example:

protected override void OnModelCreating(ModelBuilder modelBuilder)
        .ComplexProperty(e => e.Address);

The flexibility in configuration ensures that developers can mold the framework to their preferred coding style, making it adaptable to various project structures.

Complex Types for Value Objects

In the past, handling objects that held multiple values but lacked a unique identifier was a challenge. Now, objects like Address can be used across different entities without needing a separate table. This not only streamlines our database schema but also brings our models closer to the domain-driven design principles.

Code Example:

public class Address
    public required string Line1 { get; set; }
    public string? Line2 { get; set; }
    public required string City { get; set; }
    public required string Country { get; set; }
    public required string PostCode { get; set; }

This feature simplifies the representation of value objects, making our code cleaner and more maintainable.

Dec 19, 2020
SQLite and PostgreSQL are among the most widely used relational database management systems (RDMS). They are both open-source and free, but they have some major differences that should be considered when choosing a database to use for your business.1. Principle...
Dec 25, 2022
Author: Sannan Malik
This article will look at the differences between static and readonly C# fields. Basically, a static readonly field can never be replaced by an instance of a reference type. In contrast, a const constant object cannot be replaced by a...
Aug 15, 2021
.NET has a large number of built in exceptions. However, there maybe times when none of the built exceptions seem adequate for your particular scenario and you will need to create your own custom (AKA “user defined”) exception.This post focuses...
Mar 1, 2023
Author: Alper Ebiçoğlu
In this article, I’ll show you all the object mapping strategies of EF Core and especially the new one: TPC Inheritance Mapping. TPC mapping is the new feature introduced with Entity Framework Core 7. It’s called Table Per Concrete type...
Написать сообщение

© 1999–2023 WebDynamics
1980–... Sergey Drozdov
Area of interests: .NET | .NET Core | C# | ASP.NET | Windows Forms | WPF | Windows Phone | HTML5 | CSS3 | jQuery | AJAX | MS SQL Server | Transact-SQL | ADO.NET | Entity Framework | IIS | OOP | OOA | OOD | WCF | WPF | MSMQ | MVC | MVP | MVVM | Design Patterns | Enterprise Architecture | Scrum | Kanban
Boosty donation
Donate to support the project
GitHub account
GitHub profile