惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园_首页
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
酷 壳 – CoolShell
酷 壳 – CoolShell
Y
Y Combinator Blog
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
G
Google Developers Blog
Last Week in AI
Last Week in AI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
3 LINQ Mistakes That Hurt Backend API Performance in .NET
Ayman Atif · 2026-04-28 · via DEV Community

LINQ looks clean and harmless in C#.

But in real backend APIs, small mistakes can quietly turn into serious performance issues.

Here are 3 I’ve seen (and made) while working with .NET and Entity Framework:

1. Loading entire tables into memory

A common mistake is doing this:

var orders = dbContext.Orders.ToList();

var recent = orders.Where(o => o.CreatedAt > DateTime.UtcNow.AddDays(-7));

This pulls everything into memory first, then filters in C#.

The problem:

  • unnecessary memory usage
  • slow processing on large datasets
  • wasted database optimization

Fix:

Let the database do the work:

var recent = dbContext.Orders
.Where(o => o.CreatedAt > DateTime.UtcNow.AddDays(-7))
.ToList();

2. Hidden multiple database calls

LINQ queries can be deceptively reused:

var query = dbContext.Orders.Where(o => o.Total > 100);

var count = query.Count();
var list = query.ToList();

This can result in multiple database executions depending on how it's used.

Fix:

Materialize once:

var list = dbContext.Orders
.Where(o => o.Total > 100)
.ToList();

var count = list.Count;

3. Fetching more data than needed

Another common issue:

var orders = dbContext.Orders.ToList();

var result = orders.Select(o => new
{
o.Id,
o.CustomerName
});

You are still loading full rows from the database even though you only need 2 fields.

Fix:

Project early:

var result = dbContext.Orders
.Select(o => new
{
o.Id,
o.CustomerName
})
.ToList();

Key idea

LINQ itself is not the problem.

The real issue is where the execution happens:

  • in memory
  • or in the database

In backend systems, that difference matters a lot.

Closing thought

Most performance issues in APIs are not “big architecture problems”.

They start with small LINQ decisions like these.