Deleting and Updating Data Faster in EF Core with ExecuteDeleteAsync and ExecuteUpdateAsync

If you’ve been using Entity Framework Core for a while, you know that sometimes you just need to delete or update a bunch of rows quickly without the overhead of pulling them into memory first. That’s where two newer methods—ExecuteDeleteAsync and ExecuteUpdateAsync—come in handy.

Instead of looping through entities and calling SaveChanges, these methods translate directly into SQL DELETE and UPDATE statements under the hood. That means fewer round trips and better performance.

Continue reading “Deleting and Updating Data Faster in EF Core with ExecuteDeleteAsync and ExecuteUpdateAsync”

Get Distinct Object by Id and Return Full Object with C# and EF

If you’re using Entity Framework Core in C# and you want to retrieve distinct items based on a specific property (e.g., ID) but still return the full object, you can use the GroupBy method along with First or FirstOrDefault. Here’s an example assuming you have a class named YourEntity with a property named Id:

Continue reading “Get Distinct Object by Id and Return Full Object with C# and EF”

Entity Framework (EF) Core FluentApi Relationships without Navigation Properties

Entity Framework (EF) Core allows you to define relationships between entities using Fluent API, even without explicitly creating navigation properties. This can be useful when you want to define relationships between entities but don’t want to create navigation properties in your entity classes. Here’s how you can achieve this:

Continue reading “Entity Framework (EF) Core FluentApi Relationships without Navigation Properties”

Case-insensitive “LIKE” search with EF Core and PostgreSQL

When using EF Core with PostgreSQL for a case-insensitive “LIKE” search, you can leverage PostgreSQL-specific features to achieve the desired behavior. PostgreSQL supports the ILIKE operator, which performs a case-insensitive pattern matching operation. Here’s an example of how to perform a case-insensitive “LIKE” search using EF Core and PostgreSQL:

Continue reading “Case-insensitive “LIKE” search with EF Core and PostgreSQL”