{
  "id": 8858879,
  "title": "IQueryable vs IEnumerable: The Line Between C# and SQL",
  "url": "https://urgent.news/2026/09/21/iqueryable-vs-ienumerable-the-line-between-c-and-sql",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-21T06:19:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/homolibere/iqueryable-vs-ienumerable-the-line-between-c-and-sql-2kpp"
  },
  "original_language": "en",
  "account": "IEnumerable vs IQueryable: The Difference Between C# and SQL\n\nWhen filtering large data sets, the choice between IEnumerable and IQueryable can make a big difference in performance. Both use the same LINQ syntax, but their execution differs dramatically.\n\nIEnumerable:\n- Evaluates filtering in your application's memory using delegates\n- Requires loading all data into memory first\n- Becomes memory-intensive with millions of rows\n- Example: dbContext.Products.Where(p => p.Price > 100).Where(p => p.Price > 100).Take(10).ToList();\n\nIQueryable:\n- Builds an expression tree that is translated into SQL by the database provider\n- Filtering happens directly in the database, not in memory\n- Ideal for large data sets and complex queries\n- Example: dbContext.Products.Where(p => p.Price > 100).Where(p => p.Price > 100).ToList();\n\nExpression Trees:\n- IQueryable uses expression trees to represent queries as data structures\n- The lambda expression .Where(p => p.Price > 100) becomes an expression tree\n- Entity Framework walks the tree and generates SQL like:\nSELECT * FROM Products WHERE Price > 100\n\nWhen to use each:\n- Use IQueryable whenever possible to push filtering to the database\n- Switch to AsEnumerable() or ToList() only when you need C#-specific logic after filtering\n- Returning IQueryable from repositories allows callers to add their own conditions\n- Use IEnumerable (or materialized List) when the result set is final and no further filtering is needed\n\nA common mistake is casting to IEnumerable too early, causing millions of rows to be loaded into memory before any filtering occurs. Keeping IQueryable for as long as possible ensures database-intensive filtering and efficient memory usage.",
  "summary": "IQueryable vs IEnumerable: The Line Between C# and SQL You're filtering a million records. With one interface, the database does the work. With the other, your application drowns in memory. Same LINQ syntax. Wildly different execution. Let's demystify where C# ends and SQL begins. The Two Worlds IEnumerable < Product > inMemory = products . Where ( p => p . Price > 100 ); IQueryable < Product >…",
  "key_points": [
    "IEnumerable evaluates filtering in application memory using delegates",
    "IQueryable builds expression tree translated into SQL by database",
    "Use IQueryable for large data sets and complex queries"
  ],
  "editors_take": "Favoring IQueryable over IEnumerable for data filtering means that database providers handle the workload, reducing memory usage and improving performance, especially with large data sets and complex queries.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}