linq-optimization-patterns

Optimize LINQ and EF Core queries in ABP Framework applications.

Updated Jan 23, 2026
One-click install
npx skills add https://github.com/alexsandrocruz/DominusLeads --skill linq-optimization-patterns-alexsandrocruz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: linq-optimization-patterns
Source: https://github.com/alexsandrocruz/DominusLeads/tree/main/backend/Sapienza.Leads/.claude/skills/linq-optimization-patterns
Command: npx skills add https://github.com/alexsandrocruz/DominusLeads --skill linq-optimization-patterns-alexsandrocruz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps software engineers optimize LINQ and EF Core queries in ABP Framework applications, reducing N+1 queries, over-fetching, and inefficient pagination.

Core Features & Use Cases

  • Eager loading with Include/ThenInclude to fetch related data in a single query.
  • DTO projection to avoid loading full entities and improve read performance.
  • Batch loading for cross-repository data to prevent N+1 queries.
  • Efficient pagination with proper count-before-pagination patterns and optional filters.

Quick Start

Refactor a slow list API by applying Include/ThenInclude or batch loading and replace per-item queries with a single optimized query, then project to a DTO.

Frequently Asked Questions about linq-optimization-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix the N+1 query problem in my EF Core and ABP Framework applications?

Fix the N+1 query problem in EF Core by applying eager loading with Include/ThenInclude, batch loading for cross-repository data, and DTO projection to fetch related data in a single optimized query.

What is the best way to optimize slow LINQ list endpoints and dashboards in ABP?

The best way to optimize slow LINQ list endpoints is to use DTO projection to avoid loading full entities, batch loading to prevent N+1 queries, and efficient pagination with CountAsync before applying pagination filters.

How does AsSplitQuery prevent performance degradation when loading multiple collections?

AsSplitQuery prevents performance degradation by splitting a single large query into multiple smaller SQL queries, avoiding the Cartesian explosion that occurs when eagerly loading multiple related collections in EF Core.

Can I use this LINQ optimization approach for cross-repository data access in ABP Framework?

Yes, you can optimize cross-repository data access in ABP Framework by implementing batch loading patterns, which consolidate per-item queries into a single optimized query to prevent N+1 issues.

When should I project to a DTO instead of using eager loading with Include/ThenInclude?

Project to a DTO instead of using Include/ThenInclude when you need to improve read performance for list endpoints and dashboards by avoiding loading full entities, fetching only the necessary fields directly.

Why should I call CountAsync before applying pagination in my EF Core list API?

Call CountAsync before pagination to efficiently compute the total record count with optional filters applied, ensuring your pagination logic returns accurate totals without executing redundant database queries.