Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If your LINQ code loads 1,000 parent records and then triggers a separate related-data query for each one, the database may receive 1,001 queries: one for the parents and 1,000 more for their children. That pattern is called the N+1 query problem. It is not caused by a special LINQ operator, and not every loop or LINQ query produces it; the extra calls depend on how related data is loaded and accessed.

Why is my LINQ query making 1,001 database calls?

Consider an EF Core application that loads a list of 1,000 blogs and then reads each blog’s Posts navigation property:

var blogs = await context.Blogs.ToListAsync();

foreach (var blog in blogs)
{
    Console.WriteLine(blog.Posts.Count);
}

If lazy loading is enabled and the posts have not already been loaded, EF Core can issue one query to retrieve the blogs and another query when each blog’s posts are accessed. In this simple case, the arithmetic is 1 + 1,000 = 1,001 queries. Microsoft describes this pattern in its EF Core efficient-querying documentation.

The actual count depends on the navigations the code accesses, what is already loaded, filters, provider behavior, and the application’s query shape. The number 1,001 illustrates a possible query count; it is not a benchmark or a guarantee about every LINQ loop.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

What is the N+1 query problem in Entity Framework Core?

N+1 describes a database-access pattern: one query retrieves a set of parent entities, then N additional queries retrieve related data for individual parents. The LINQ expression itself is not necessarily the problem. The key is whether accessing related data causes more database work.

Lazy loading can make that work implicit: reading a navigation property may cause EF Core to fetch its data at that point. In the documented proxy approach, lazy loading requires the relevant proxies and navigation properties to be configured for it; it is not an automatic consequence of using LINQ. Microsoft warns that lazy loading can produce unnecessary round trips and recommends making database work clear in the code where appropriate. See the lazy-loading documentation.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

How do I stop EF Core from running a query for every row?

Choose a loading strategy based on which related data the operation actually needs. When related data is known in advance, retrieve it as part of the query—either by eager loading or by projecting only the required values. When the need is conditional, explicit loading can make the later database operation visible, but repeating it for every parent can still create N+1 behavior.

Use eager loading when you need related entities

Include and ThenInclude tell EF Core to load related data with the query:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
var blogs = await context.Blogs
    .Include(blog => blog.Posts)
    .ToListAsync();

Use this shape when the operation genuinely needs the blog entities and their posts. For deeper relationships, ThenInclude specifies further navigations. The generated SQL and exact execution behavior depend on the EF Core version and database provider, so check the commands your application actually sends. Microsoft documents eager loading with Include and ThenInclude.

Project only the data a read operation needs

If a response needs selected fields rather than full entity objects, a projection can avoid fetching unnecessary columns and shape related values for the result:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
var blogs = await context.Blogs
    .Select(blog => new
    {
        blog.Url,
        Posts = blog.Posts.Select(post => post.Title)
    })
    .ToListAsync();

This asks for each blog URL and its post titles rather than loading complete blog and post entities. You can also constrain related rows with a filtered include where that fits the query. Inspect the generated commands to confirm the result for your EF Core version and provider; query translation and tracking behavior are not identical across all setups.

Use explicit loading for conditional or selected parents

Explicit loading is useful when the application decides later that it needs a navigation, or only needs it for selected parents. It makes the additional database operation apparent in code, but it does not eliminate that work. If the application explicitly loads a collection once for every parent, it can recreate the same N+1 pattern. EF Core also supports querying a navigation collection to filter its rows or calculate an aggregate without loading the entire collection into memory. See Microsoft’s explicit-loading documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When is a split query better than one joined query?

A single query that includes multiple collections can produce a large joined result, repeating parent columns across rows. EF Core split queries fetch related data through separate SQL queries and can reduce that duplication. They are a trade-off, not a universal fix: the current implementation described in Microsoft’s performance guidance performs a round trip for each query, and separate executions can observe changes made between them.

Microsoft’s EF Core 5.0 release documentation introduced split queries and notes the possible consistency issue when data changes between executions. A suitable serializable or snapshot transaction can mitigate that risk, though transaction isolation can add performance costs. Because the cited release page is historical feature documentation, confirm behavior and available APIs for the EF Core version and provider used by your application. See What’s New in EF Core 5.0.

Which loading strategy should I choose?

Approach Best fit Trade-off to check
Eager loading with Include or a projection The operation needs related data for the parent set. A joined result can repeat parent data; a projection can limit selected fields. Check the generated SQL and payload.
Explicit or targeted loading The application needs related data later or only for selected parents. Each load can require database work. Repeating it across all parents can still cause N+1 calls.
Split query A query with multiple included collections would otherwise produce costly row duplication. Separate query executions add round trips and may observe intervening changes.

Compare the options against the data and consistency requirements of the operation:

  • Round trips: count the statements sent for a joined query, a split query, or conditional loads.
  • Rows and payload: check for repeated parent columns or fields the application never uses.
  • Needed related data: decide whether you need all children, filtered children, data for selected parents, or only an aggregate such as a count.
  • Consistency: decide whether separate query executions may observe intervening writes and whether transaction isolation is appropriate.
  • Observed performance: compare query counts and timings in representative application conditions. Microsoft notes that separate queries can be more efficient in some scenarios, while extra round trips are especially costly when network latency is high; the result should be measured in the target application. See the ASP.NET Core 10.0 tutorial on reading related data.

How can I verify whether a query causes N+1 behavior?

Inspect EF Core’s database command logs or generated SQL around the code that accesses the suspected navigation. Count the statements and check whether a similar related-data query repeats for each parent. Then compare the command count and representative timings after changing the query shape.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not infer the performance cost from the query count alone. The official guidance explains the round-trip trade-off but does not establish a universal time or percentage penalty for 1,001 calls. Network latency, result size, database load, provider behavior, and application conditions affect what you observe.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.