Entity Framework Core makes it very easy to retrieve related data from a database. With methods such as Include() and ThenInclude(), developers can load related entities without writing SQL joins manually.
This convenience is one of the reasons EF Core is widely used in ASP.NET Core applications.
However, there is something developers often overlook: just because we can load related data doesn't mean we should load all of it.
Consider a customer management application. You have a customer table, an orders table, and an order items table. When displaying a list of customers, the application only needs the customer name, email address, and the total number of orders.
But the developer writes a query using Include() to retrieve customers, their orders, and all the order items.
The query works perfectly. The API returns the expected information, and there are no errors. But the application is retrieving much more data than it actually needs.
Initially, this might not seem like a problem. When the database contains a few hundred records, everything may work smoothly. But as the application grows, the same query can start consuming more memory, transferring unnecessary data, and increasing database execution time.
This is one of the common reasons why an EF Core application performs well during development but starts experiencing performance problems in production.
The solution is not to stop using Include(). Instead, developers need to understand when related entities are actually required and when a simpler query can do the job.
In this article, we'll understand why unnecessary Include() statements can affect performance, how to identify them, and how to write more efficient EF Core queries using projection, filtered Include, split queries, and other practical techniques.
Understanding How Include() Works in EF Core
Before discussing optimization, let's understand what Include() actually does.
Entity Framework Core supports three ways of loading related data:
Eager loading: Loads related entities as part of the original query using Include() and ThenInclude().
Explicit loading: Loads related entities when the application specifically requests them.
Lazy loading: Loads related entities automatically when their navigation properties are accessed.
Eager loading is commonly used in ASP.NET Core applications because developers can specify which related entities should be retrieved.
Let's take a simple e-commerce application as an example.
It contains three main entities:
A customer can place multiple orders, and each order can contain multiple items.
Here are the corresponding entity classes:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string PhoneNumber { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public ICollection<Order> Orders { get; set; }
= new List<Order>();
}
public class Order
{
public int Id { get; set; }
public DateTime OrderDate { get; set; }
public decimal TotalAmount { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; } = null!;
public ICollection<OrderItem> Items { get; set; }
= new List<OrderItem>();
}
public class OrderItem
{
public int Id { get; set; }
public string ProductName { get; set; } = string.Empty;
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public int OrderId { get; set; }
public Order Order { get; set; } = null!;
}
These classes represent the relationships between customers, orders, and order items.
Now suppose we want to retrieve customers along with their orders and the items associated with each order.
We can write the following query:
var customers = await dbContext.Customers
.Include(c => c.Orders)
.ThenInclude(o => o.Items)
.ToListAsync();
This is a perfectly valid EF Core query.
The Include() method loads the customer's orders, while ThenInclude() loads the order items associated with each order.
EF Core generates SQL to retrieve the required data, typically using LEFT JOIN operations.
The generated SQL might look similar to this:
SELECT
c.Id,
c.Name,
c.Email,
c.PhoneNumber,
c.Address,
o.Id AS OrderId,
o.OrderDate,
o.TotalAmount,
oi.Id AS OrderItemId,
oi.ProductName,
oi.Quantity,
oi.UnitPrice
FROM Customers c
LEFT JOIN Orders o
ON c.Id = o.CustomerId
LEFT JOIN OrderItems oi
ON o.Id = oi.OrderId;
The actual SQL depends on the database provider and EF Core query configuration.
This approach makes sense when the application needs complete customer, order, and order-item information.
But let's change the requirement.
Suppose the API only displays the following information:
Customer ID
Customer name
Email address
Total number of orders
Do we really need to load every order and order item?
Of course not.
We only need a few customer properties and an order count. Loading the complete entity graph would be unnecessary.
This is where understanding the difference between loading related entities and selecting related information becomes important.
Why Loading Unnecessary Related Data Affects Performance
Using Include() is not a performance problem by itself. Problems usually appear when developers include relationships without considering how the returned data will be used.
There are several reasons why unnecessary data loading can affect application performance.
More Data Retrieved From the Database
Every additional relationship can increase the amount of data returned by a query.
Consider the following example database:
Entity | Records |
|---|
Customers | 1,000 |
Orders | 10,000 |
OrderItems | 50,000 |
Suppose an API retrieves 100 customers.
If the query includes orders and order items, EF Core may retrieve thousands of related records, depending on the relationships.
However, if the API only needs customer names and order counts, most of that information is unnecessary.
The database still needs to execute the joins, process the query, and return the selected columns.
When applications retrieve only the information they need, they can reduce the amount of data transferred between the database and application server.
This becomes particularly important when an application handles large datasets or serves multiple requests simultaneously.
Higher Memory Consumption
Retrieving data from the database is only one part of the process.
EF Core also converts database results into .NET objects. This process is called materialization.
For tracking queries, EF Core additionally maintains entity information in its change tracker.
Consider this query:
var customers = await dbContext.Customers
.Include(c => c.Orders)
.ThenInclude(o => o.Items)
.ToListAsync();
Depending on the database records, the application may create:
All these objects consume memory.
When a request loads thousands of related records, memory consumption can increase considerably.
Now imagine multiple API requests executing the same query at the same time.
The application may need to hold several large entity graphs in memory simultaneously.
This is why unnecessary entity loading can become a problem in high-traffic applications.
More Network Traffic
Database servers and application servers frequently communicate over a network.
When a query retrieves unnecessary columns and related records, the database has to transfer additional information to the application.
For example, a customer entity might contain:
Name
Email
Phone number
Address
Profile image
Additional metadata
If an API only displays the customer's name and email address, retrieving all these fields provides no real benefit.
The difference becomes more noticeable when tables contain large text columns, binary data, or multiple collection relationships.
Selecting only the required columns helps reduce unnecessary network traffic.
Cartesian Explosion When Including Multiple Collections
Another important problem developers should understand is Cartesian explosion.
This commonly happens when a query includes multiple collection navigation properties at the same level.
Suppose a customer has two collections:
A developer writes:
var customers = await dbContext.Customers
.Include(c => c.Orders)
.Include(c => c.Addresses)
.ToListAsync();
Now imagine one customer has:
When EF Core retrieves both collections using a single SQL query with joins, the database can produce 50 rows for that customer.
The reason is that the two independent collections are combined in the SQL result.
Conceptually:
10 Orders × 5 Addresses = 50 Rows
This means information about the same customer and orders may appear repeatedly across the result set.
EF Core handles relationship resolution when materializing the entities, but the database still returns those multiplied rows.
As the number of included collections increases, the result can become considerably larger.
It is worth understanding the difference between sibling collections and nested collections.
For example:
.Include(c => c.Orders)
.ThenInclude(o => o.Items)
This loads a nested relationship. It does not create the same sibling collection cross-product as independently including orders and addresses.
Understanding this distinction helps developers identify which queries are likely to create Cartesian explosion.
Avoid Unnecessary Include() Using Projection
One of the simplest and most effective ways to reduce unnecessary data loading is projection.
Projection means selecting only the properties required by the application instead of retrieving complete entities.
In EF Core, we commonly use the LINQ Select() method for this purpose.
Let's return to our customer API example.
The API needs:
Customer ID
Customer name
Email address
Total number of orders
Instead of loading customers with their complete order collections, we can write:
var customers = await dbContext.Customers
.Select(c => new
{
c.Id,
c.Name,
c.Email,
OrderCount = c.Orders.Count()
})
.ToListAsync();
Look at the difference.
We are no longer loading every order just to calculate how many orders a customer has.
We are asking EF Core to retrieve the customer properties and calculate the order count as part of the database query.
The generated SQL might look similar to this:
SELECT
c.Id,
c.Name,
c.Email,
(
SELECT COUNT(*)
FROM Orders o
WHERE o.CustomerId = c.Id
) AS OrderCount
FROM Customers c;
The actual SQL may vary depending on the database provider and EF Core version.
The important point is that the database calculates the count instead of requiring the application to materialize every order.
This can significantly reduce the amount of data transferred and the number of objects created by EF Core.
Use DTOs Instead of Anonymous Objects
Anonymous objects are useful when demonstrating projection, but in production applications, dedicated Data Transfer Objects are generally a better choice.
A DTO defines exactly what information an application wants to return.
Let's create a customer response model:
public class CustomerSummaryDto
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public int OrderCount { get; set; }
}
Now we can update our query:
var customers = await dbContext.Customers
.Select(c => new CustomerSummaryDto
{
Id = c.Id,
Name = c.Name,
Email = c.Email,
OrderCount = c.Orders.Count()
})
.ToListAsync();
This approach has several advantages.
First, the query retrieves only the properties required by the API.
Second, the response structure is independent of the database entity.
Third, the application does not need to materialize the complete order collection.
Finally, changes to the database entity do not automatically expose additional properties through the API.
For read-heavy endpoints, DTO projection is often a better starting point than loading complete entity graphs.
Projection With Multiple Related Entities
Projection is not limited to simple customer queries.
You can also retrieve selected information from multiple related entities.
Suppose an order history API needs to display:
Order ID
Order date
Total amount
Customer name
Number of items
We can write:
var orders = await dbContext.Orders
.Select(o => new
{
o.Id,
o.OrderDate,
o.TotalAmount,
CustomerName = o.Customer.Name,
ItemCount = o.Items.Count()
})
.ToListAsync();
EF Core translates the navigation property expressions into the required SQL operations.
There is no need to explicitly call Include() simply to access these properties inside a projection.
This is an important concept to understand.
You can retrieve information from related tables through projection without loading complete related entities.
However, there is one detail worth remembering.
If your projection contains an actual entity instance, EF Core may still track that entity.
For example:
var result = await dbContext.Orders
.Select(o => new
{
Order = o,
CustomerName = o.Customer.Name
})
.ToListAsync();
Here, the Order entity is included in the result and is tracked by default.
When building read-only DTOs containing only scalar properties and other DTOs, there are generally no entity instances to track.
Use Filtered Include When You Need Only Specific Related Records
Projection is an excellent option when the application needs selected information.
But sometimes the application genuinely needs related entity objects.
For example, imagine an order management application where the customer details screen displays only the five most recent orders.
Loading every historical order would be unnecessary.
EF Core supports filtered Include, which allows developers to filter, sort, and limit collection navigation properties.
Consider the following query:
var customers = await dbContext.Customers
.Include(c => c.Orders
.OrderByDescending(o => o.OrderDate)
.Take(5))
.ToListAsync();
This query loads customers with up to five of their most recent orders.
Filtered Include supports the following operations on collection navigation properties:
Where()
OrderBy()
OrderByDescending()
ThenBy()
ThenByDescending()
Skip()
Take()
You can also combine filtering and sorting:
var customers = await dbContext.Customers
.Include(c => c.Orders
.Where(o => o.TotalAmount > 1000)
.OrderByDescending(o => o.OrderDate)
.Take(5))
.ToListAsync();
This retrieves up to five orders per customer where the total amount is greater than 1000.
Filtered Include is useful when the application needs actual related entities but does not need the complete collection.
Be Careful With Filtered Include and Change Tracking
There is an important behavior that developers sometimes overlook when using filtered Include.
EF Core performs something called navigation fix-up.
This means that when entities are already being tracked by the current DbContext, EF Core can automatically connect related entities through their navigation properties.
Consider the following query:
var existingOrders = await dbContext.Orders
.Where(o => o.TotalAmount > 500)
.ToListAsync();
Now suppose we execute another query:
var customers = await dbContext.Customers
.Include(c => c.Orders
.Where(o => o.TotalAmount > 1000))
.ToListAsync();
You might expect each customer's Orders collection to contain only orders above 1000.
However, orders that were already tracked by the DbContext can also appear in the navigation collection because of navigation fix-up.
This can produce unexpected results.
For read-only queries, one option is to use AsNoTracking():
var customers = await dbContext.Customers
.AsNoTracking()
.Include(c => c.Orders
.Where(o => o.TotalAmount > 1000))
.ToListAsync();
Another option is to use a fresh DbContext when a clean tracking state is required.
There is one more important detail.
In a tracking query, EF Core considers a filtered navigation property loaded, even if some related records were intentionally excluded.
Therefore, developers should not assume that lazy loading or explicit loading will automatically retrieve the remaining records later.
Use AsSplitQuery() When Multiple Collections Are Required
Projection and filtered Include solve different problems.
But what happens when the application genuinely needs multiple complete collections?
For example, an administrative screen might need:
In this situation, using Include() may be necessary.
However, retrieving multiple collections through a single SQL query can create Cartesian explosion.
EF Core provides AsSplitQuery() to help with this situation.
Consider:
var customers = await dbContext.Customers
.Include(c => c.Orders)
.Include(c => c.Addresses)
.AsSplitQuery()
.ToListAsync();
Instead of retrieving everything through one large SQL query, EF Core executes separate SQL queries for the included collections.
Conceptually, the execution looks like this:
-- Retrieve customers
SELECT *
FROM Customers;
-- Retrieve customer orders
SELECT o.*
FROM Orders o
INNER JOIN Customers c
ON c.Id = o.CustomerId;
-- Retrieve customer addresses
SELECT a.*
FROM Addresses a
INNER JOIN Customers c
ON c.Id = a.CustomerId;
The actual generated SQL includes additional information required to associate the results correctly.
The advantage is that separate queries avoid multiplying sibling collection rows into one large result set.
When Should You Use AsSplitQuery()?
Consider split queries when:
Multiple collection relationships must be loaded.
A single query produces excessive duplicated rows.
Parent entities contain large columns.
Query execution plans indicate that a large join is becoming expensive.
However, AsSplitQuery() is not automatically faster in every situation.
It also has some trade-offs.
A single query generally requires fewer database round trips, while a split query executes additional SQL statements.
This means network latency can affect split-query performance.
There is also a consistency consideration.
Because multiple SQL statements are executed, concurrent database changes can result in inconsistent results across those statements.
If the application requires a consistent view of the data, consider using an appropriate transaction isolation level, such as snapshot or serializable isolation where supported by the database.
One more detail is worth mentioning.
When using Skip() and Take() with split queries in EF Core versions before EF Core 10, make sure the ordering is fully unique. Otherwise, separate queries might select different records for the same page.
The right choice depends on the actual query, database provider, data volume, and application requirements.
Use AsNoTracking() for Read-Only Queries
Another useful optimization is avoiding unnecessary change tracking.
By default, EF Core tracks entities returned from queries.
This allows EF Core to identify changes to entity properties and persist those changes when SaveChanges() is called.
However, not every query needs change tracking.
Consider a customer listing API that only displays customer information.
We can write:
var customers = await dbContext.Customers
.AsNoTracking()
.ToListAsync();
The AsNoTracking() method tells EF Core that the returned entities do not need to be tracked by the current DbContext.
This can reduce the overhead associated with tracking entities, especially when retrieving large read-only result sets.
You can also combine it with Include():
var customers = await dbContext.Customers
.AsNoTracking()
.Include(c => c.Orders)
.ToListAsync();
This still retrieves customer entities and their related orders, but avoids normal change tracking.
However, remember that AsNoTracking() does not reduce the number of columns or related records retrieved from the database.
It optimizes entity tracking, not the SQL result size.
If the application only needs a few properties, projection is still the better approach.
Understanding AsNoTrackingWithIdentityResolution()
EF Core also provides another option called AsNoTrackingWithIdentityResolution().
Consider a query that retrieves multiple rows representing relationships to the same entity.
In a normal no-tracking query, EF Core may create separate instances of the same entity when it appears multiple times in the result.
Identity resolution ensures that the same database entity is represented by the same object instance within the query results.
For example:
var customers = await dbContext.Customers
.AsNoTrackingWithIdentityResolution()
.Include(c => c.Orders)
.ToListAsync();
This provides identity resolution without adding the returned entities to the DbContext's normal change tracker.
It is useful when loading read-only entity graphs where maintaining object identity matters.
However, it introduces additional processing and memory overhead compared with regular no-tracking queries.
Use it when the query actually benefits from identity resolution.
Avoid Loading Complete Entity Graphs in API Endpoints
One common mistake in ASP.NET Core applications is using the same entity-loading approach for every API endpoint.
Let's consider a customer management application with four endpoints:
API Endpoint | Required Information |
|---|
Customer List | Name, email, order count |
Customer Details | Customer information and recent orders |
Order Details | Order, customer name, order items |
Admin Customer Management | Complete customer relationships |
Each endpoint has different data requirements.
Using the same large Include() query for all four endpoints can introduce unnecessary database work.
A better approach is to design each query around the actual response required by that endpoint.
Customer List API
For a listing endpoint, projection is generally a good choice.
public async Task<List<CustomerSummaryDto>> GetCustomersAsync()
{
return await dbContext.Customers
.AsNoTracking()
.Select(c => new CustomerSummaryDto
{
Id = c.Id,
Name = c.Name,
Email = c.Email,
OrderCount = c.Orders.Count()
})
.ToListAsync();
}
This retrieves only the information required by the listing screen.
Customer Details API
A details endpoint might need customer information and recent orders.
We can still use projection instead of loading the complete entity graph.
public async Task<CustomerDetailsDto?> GetCustomerAsync(int customerId)
{
return await dbContext.Customers
.AsNoTracking()
.Where(c => c.Id == customerId)
.Select(c => new CustomerDetailsDto
{
Id = c.Id,
Name = c.Name,
Email = c.Email,
Orders = c.Orders
.OrderByDescending(o => o.OrderDate)
.Take(5)
.Select(o => new OrderSummaryDto
{
Id = o.Id,
OrderDate = o.OrderDate,
TotalAmount = o.TotalAmount,
ItemCount = o.Items.Count()
})
.ToList()
})
.FirstOrDefaultAsync();
}
The corresponding DTOs might look like this:
public class CustomerDetailsDto
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public List<OrderSummaryDto> Orders { get; set; }
= new();
}
public class OrderSummaryDto
{
public int Id { get; set; }
public DateTime OrderDate { get; set; }
public decimal TotalAmount { get; set; }
public int ItemCount { get; set; }
}
This query retrieves the five most recent orders and calculates their item counts without materializing the complete order-item entity collections.
The exact SQL translation depends on the EF Core version and database provider, so it is always worth inspecting the generated SQL when optimizing more complex projections.
The main idea is simple: each API endpoint should retrieve the information it actually needs.
Be Careful With Lazy Loading and the N+1 Query Problem
Removing unnecessary Include() statements does not mean developers should blindly depend on lazy loading.
Lazy loading automatically retrieves related data when a navigation property is accessed.
For example:
var customers = await dbContext.Customers
.ToListAsync();
foreach (var customer in customers)
{
Console.WriteLine(customer.Orders.Count);
}
If lazy loading is enabled, accessing customer.Orders can trigger another database query for each customer.
Suppose the application retrieves 100 customers.
The database might receive:
This is known as the N+1 query problem.
The code looks simple, but it can generate a large number of database requests.
For a customer listing API that only needs order counts, projection is a much better choice:
var customers = await dbContext.Customers
.Select(c => new
{
c.Id,
c.Name,
OrderCount = c.Orders.Count()
})
.ToListAsync();
This allows EF Core to translate the count operation into SQL instead of issuing a separate query for every customer.
For web applications, projection and explicit eager loading are generally easier to reason about because the required database operations are visible in the query itself.
Inspect the SQL Generated by EF Core
One of the most important habits when optimizing EF Core queries is inspecting the actual SQL generated by the framework.
A LINQ query might look efficient in C#, but the generated SQL determines what the database actually executes.
EF Core provides the ToQueryString() method to inspect the SQL representation of an IQueryable.
For example:
var query = dbContext.Customers
.Include(c => c.Orders)
.ThenInclude(o => o.Items);
var sql = query.ToQueryString();
Console.WriteLine(sql);
This displays the SQL generated for the query without executing it.
Now compare it with a projection-based query:
var query = dbContext.Customers
.Select(c => new
{
c.Id,
c.Name,
c.Email,
OrderCount = c.Orders.Count()
});
Console.WriteLine(query.ToQueryString());
Comparing the two queries helps identify:
Unnecessary joins.
Additional selected columns.
Large collection relationships.
Unexpected SQL expressions.
Potential query complexity.
Enable EF Core Query Logging
You can also enable database command logging through the application's logging configuration.
For example:
builder.Services.AddDbContext<AppDbContext>(options =>
{
options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection"));
options.LogTo(
Console.WriteLine,
LogLevel.Information);
});
This configuration is useful during development because it allows you to observe the SQL commands executed by EF Core.
For production applications, use structured logging and appropriate log filtering rather than writing every database command directly to the console.
Also be careful with sensitive information.
Avoid enabling sensitive-data logging in production unless you have a controlled reason and understand the privacy implications.
Measure Query Performance Instead of Guessing
Do not assume that a query is faster simply because it contains fewer Include() statements.
A good performance investigation should compare:
SQL execution time.
Number of database round trips.
Number of rows returned.
Amount of data transferred.
Application memory allocations.
Entity materialization and tracking overhead.
Execution plans and index usage.
For example, a projection that calculates several aggregates might generate expensive SQL even though it returns only a few columns.
Similarly, a split query may transfer less duplicated data but introduce additional network round trips.
Use representative production-like data to measure the actual difference.
Common Mistakes Developers Should Avoid
Before wrapping up, let's look at some mistakes that frequently appear in EF Core applications.
Removing every Include() statement without understanding the requirement
Include() is not bad practice. If an application needs complete related entities, eager loading is an appropriate solution. The objective is to avoid unnecessary loading, not eliminate eager loading.
Using AsNoTracking() as a replacement for projection
No-tracking queries reduce change-tracking overhead, but they do not automatically reduce the number of selected columns. Use projection when you need fewer fields.
Assuming Filtered Include always returns only filtered records
Previously tracked entities can appear through navigation fix-up. Understand the behavior of the current DbContext before relying on filtered navigation collections.
Using AsSplitQuery() everywhere
Split queries can prevent Cartesian explosion, but additional database round trips can affect performance. Choose between single and split queries based on actual measurements.
Ignoring generated SQL
A short LINQ expression does not necessarily produce an efficient database query. Always inspect SQL and execution plans when performance matters.
Loading every record without pagination
Even an optimized projection can become expensive when it retrieves hundreds of thousands of records. Apply appropriate filtering and pagination.
Practical Guidelines for Choosing the Right Query
There is no single query pattern that works best for every application.
The following guidelines can help you decide which approach to use.
Requirement | Recommended Approach |
|---|
Retrieve complete parent and child entities | Include() |
Retrieve nested related entities | Include() with ThenInclude() |
Retrieve selected properties | Select() projection |
Return API response models | DTO projection |
Retrieve only a few related records | Filtered Include() or projection |
Load multiple large collections | Evaluate AsSplitQuery() |
Execute read-only entity queries | AsNoTracking() |
Preserve object identity without normal tracking | AsNoTrackingWithIdentityResolution() |
Calculate related record counts | Count() inside projection |
Retrieve only the required page | Filtering and pagination with Skip() and Take() |
Additional Recommendations for Production Applications
Avoid unbounded collection loading.
A customer with thousands of orders should not automatically return every order through a details API. Apply pagination or explicit limits.
Use database indexes appropriately.
Relationships and filters frequently depend on foreign keys and other indexed columns. Verify the execution plan rather than assuming an index is being used.
Keep DbContext lifetimes short.
In typical ASP.NET Core applications, use a scoped DbContext per request. Long-lived contexts can accumulate tracked entities and introduce unexpected navigation fix-up behavior.
Avoid returning EF Core entities directly from APIs.
DTOs give you control over response fields, reduce accidental data exposure, and prevent your API contract from being tightly coupled to your database model.
Do not optimize based on Include() count alone.
One necessary collection Include() may be perfectly reasonable, while a complicated projection can still generate expensive SQL. Evaluate the actual query shape.
Use pagination for large datasets.
Even when a query retrieves only three columns, returning hundreds of thousands of records can consume significant resources. Use appropriate pagination and filtering.
Conclusion
Entity Framework Core makes it easy to retrieve related data through Include() and ThenInclude(). However, loading complete entity graphs when an application only needs a few properties can introduce unnecessary database operations, increase memory consumption, and affect API performance.
The most important thing is to understand what the application actually needs before writing the query.
Use Include() when complete related entities are required. Prefer projection with Select() when building API responses or retrieving selected properties. Use filtered Include() when only specific related records are needed, and consider AsSplitQuery() when multiple collection relationships create expensive joins.
For read-only operations, AsNoTracking() can further reduce change-tracking overhead.
Most importantly, inspect the generated SQL and measure query performance using realistic data.
A well-designed EF Core query is not necessarily the one with the fewest lines of code. It is the one that retrieves the required data efficiently without introducing unnecessary work for the database or application.
Join the conversation! Your thoughts help the community grow.