EntityFrameworkCore Archives - Code Maze https://code-maze.com/category/entityframeworkcore/ Learn. Code. Succeed. Thu, 23 Jan 2025 11:08:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.5 https://code-maze.com/wp-content/uploads/2020/01/Code-Maze-Favicon.png EntityFrameworkCore Archives - Code Maze https://code-maze.com/category/entityframeworkcore/ 32 32 Testing Database Connectivity with EF Core https://code-maze.com/efcore-testing-database-connectivity/ https://code-maze.com/efcore-testing-database-connectivity/#comments Thu, 23 Jan 2025 11:08:23 +0000 https://code-maze.com/?p=123759 Whether during application startup, multi-step workflows, or monitoring an application’s overall health, verifying database connectivity is essential for smooth operation and graceful handling of potential failures. It improves reliability and the overall user experience. In modern containerized environments, often managed by orchestrators like Kubernetes (K8S), it’s equally important for services to report their health status. […]

The post Testing Database Connectivity with EF Core appeared first on Code Maze.

]]>
https://code-maze.com/efcore-testing-database-connectivity/feed/ 2
Global Query Filters in Entity Framework Core https://code-maze.com/efcore-global-query-filters/ https://code-maze.com/efcore-global-query-filters/#comments Mon, 23 Dec 2024 04:47:32 +0000 https://code-maze.com/?p=123732 In this article, we will discuss Entity Framework Core’s global query filters and how to use them. We will also consider other scenarios related to using query filters that we need to be aware of. Let’s dive in. What Is a Global Query Filter? Global query filters are a handy feature of Entity Framework (EF) […]

The post Global Query Filters in Entity Framework Core appeared first on Code Maze.

]]>
https://code-maze.com/efcore-global-query-filters/feed/ 3
How to Connect a SQLite Database to EF Core https://code-maze.com/efcore-how-to-connect-a-sqlite-database/ https://code-maze.com/efcore-how-to-connect-a-sqlite-database/#respond Mon, 02 Dec 2024 06:26:38 +0000 https://code-maze.com/?p=123694 In this article, we’ll discuss connecting a SQLite database to an ASP.NET Core Web API using EF Core. So, let’s get going. Introduction to SQLite SQLite is a compact and efficient relational database management system that can be embedded directly into applications. The entire database is self-contained in a single disk file. As a result, […]

The post How to Connect a SQLite Database to EF Core appeared first on Code Maze.

]]>
https://code-maze.com/efcore-how-to-connect-a-sqlite-database/feed/ 0
Entity Framework Core Best Practices https://code-maze.com/entity-framework-core-best-practices/ https://code-maze.com/entity-framework-core-best-practices/#comments Mon, 21 Oct 2024 04:47:44 +0000 https://code-maze.com/?p=123550 Entity Framework Core (EF Core) is an object-relational mapper (ORM), enabling us to work with a database using .NET objects, eliminating much of the data-access code we usually need to write. EF Core supports many databases, including SQL Server, SQLite, PostgreSQL, MySQL, and more, making it highly versatile. While EF Core provides many conveniences, following […]

The post Entity Framework Core Best Practices appeared first on Code Maze.

]]>
https://code-maze.com/entity-framework-core-best-practices/feed/ 2
Using EF Core Interceptors in .NET https://code-maze.com/efcore-interceptors/ https://code-maze.com/efcore-interceptors/#respond Wed, 17 Jul 2024 05:14:01 +0000 https://code-maze.com/?p=120448 Entity Framework Core (EF Core) has many powerful features, with Interceptors being one of the most versatile. Interceptors allow us to plug in custom behavior at different stages of the EF Core operation pipeline, giving us enhanced control over data interaction processes. Moreover, by using interceptors, we can fine-tune our database operations, enforce business rules, […]

The post Using EF Core Interceptors in .NET appeared first on Code Maze.

]]>
https://code-maze.com/efcore-interceptors/feed/ 0
How to Show the Generated SQL Query in EF Core https://code-maze.com/efcore-show-generated-sql-query/ https://code-maze.com/efcore-show-generated-sql-query/#respond Thu, 25 Apr 2024 06:22:44 +0000 https://code-maze.com/?p=116511 Entity Framework Core has many useful features, and in this article, we will see how to use it to show a generated SQL query. EF Core is an open source Object-relational mapper that supports several databases like SQLite, PostgreSQL, MySQL, and also LINQ (Language Integrated Query). One key benefit to developers is the ability to […]

The post How to Show the Generated SQL Query in EF Core appeared first on Code Maze.

]]>
https://code-maze.com/efcore-show-generated-sql-query/feed/ 0
How to Use Entity Framework Core Migrations in Production https://code-maze.com/efcore-how-to-use-entity-framework-core-migrations-in-production/ https://code-maze.com/efcore-how-to-use-entity-framework-core-migrations-in-production/#comments Wed, 27 Mar 2024 11:48:43 +0000 https://code-maze.com/?p=110054 In this article, we will discuss the different approaches to migrating a production database when using Entity Framework (EF) Core code-first migrations. Let’s start. Entity Framework Core Project Setup Let’s start by creating a template Web API project and installing the necessary Entity Framework Core NuGet packages: Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Design In this article, we use […]

The post How to Use Entity Framework Core Migrations in Production appeared first on Code Maze.

]]>
https://code-maze.com/efcore-how-to-use-entity-framework-core-migrations-in-production/feed/ 2
Why Do We Use the Virtual Keyword for Class Properties in EF Core? https://code-maze.com/efcore-why-do-we-use-the-virtual-keyword-for-class-properties/ https://code-maze.com/efcore-why-do-we-use-the-virtual-keyword-for-class-properties/#respond Sun, 24 Mar 2024 09:15:17 +0000 https://code-maze.com/?p=109993 Many .NET applications use Entity Framework Core (EF Core), a popular ORM framework. It offers three distinct approaches to loading related data – eager loading, lazy loading, and explicit loading. In this article, we will focus on the mechanism of lazy loading and why we use the virtual keyword for navigation class properties in EF […]

The post Why Do We Use the Virtual Keyword for Class Properties in EF Core? appeared first on Code Maze.

]]>
https://code-maze.com/efcore-why-do-we-use-the-virtual-keyword-for-class-properties/feed/ 0
How to Add Unique Constraints to a Property in EF Core Code-First https://code-maze.com/efcore-add-unique-constraints-to-a-property-code-first/ https://code-maze.com/efcore-add-unique-constraints-to-a-property-code-first/#respond Wed, 28 Feb 2024 23:42:43 +0000 https://code-maze.com/?p=109680 In this article, we’ll see how we can apply unique constraints to a property in EF (Entity Framework) Core using the code-first approach. Let’s start coding! Minimal API Setup For this article, we’ll create a mini-version of our solar system contained in a minimal API: app.MapPost("/planets", async (Planet planet, SolarSystemDbContext context) => { try { […]

The post How to Add Unique Constraints to a Property in EF Core Code-First appeared first on Code Maze.

]]>
https://code-maze.com/efcore-add-unique-constraints-to-a-property-code-first/feed/ 0
How to Inject a DbContext Instance Into an IHostedService https://code-maze.com/efcore-inject-dbcontext-instance-into-ihostedservice/ https://code-maze.com/efcore-inject-dbcontext-instance-into-ihostedservice/#respond Mon, 26 Feb 2024 06:26:11 +0000 https://code-maze.com/?p=109634 In this article, we’ll take a look at how to inject a DbContext instance into an IHostedService. We’ll also point out some important concepts we should be aware of. Let’s start! Why We Cannot Inject DbContext Into an IHostedService Directly The main reason we cannot inject a DbContext instance into an IHostedService one is the […]

The post How to Inject a DbContext Instance Into an IHostedService appeared first on Code Maze.

]]>
https://code-maze.com/efcore-inject-dbcontext-instance-into-ihostedservice/feed/ 0