Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access

Tag: Any vs Count

C#

LINQ Performance Trap: Why .Any() Is 10,000x Faster Than .Count() > 0

- 01.02.26 - ErcanOPAK comment on LINQ Performance Trap: Why .Any() Is 10,000x Faster Than .Count() > 0

Using .Count() > 0 to check if a collection has items? You’re forcing LINQ to enumerate the entire collection just to answer a yes/no question. The Performance Killer: var users = dbContext.Users.Where(u => u.IsActive); // BAD: Counts ALL active users first if (users.Count() > 0) { Console.WriteLine(“We have active users”); } // Database query generated: […]

Read More
February 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
232425262728  
« Jan    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (934)
  • How to add default value for Entity Framework migrations for DateTime and Bool (830)
  • Get the First and Last Word from a String or Sentence in SQL (822)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (708)
  • Add Constraint to SQL Table to ensure email contains @ (571)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (552)
  • Average of all values in a column that are not zero in SQL (517)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (473)
  • Find numbers with more than two decimal places in SQL (436)

Recent Posts

  • Visual Studio: Pin Variables While Debugging to Track Values Across Sessions
  • C#: Use Target-Typed new Expressions to Reduce Verbosity
  • C#: Use nameof Operator to Avoid Magic Strings
  • C#: Use String Interpolation with Alignment for Formatted Output
  • SQL: Use EXISTS Instead of COUNT for Checking Existence
  • SQL: Use COALESCE to Replace NULL Values Inline
  • .NET Core: Use File-Scoped Namespaces to Reduce Indentation
  • .NET Core: Use Top-Level Statements to Skip Program Class Boilerplate
  • Git: Stash Untracked Files with –include-untracked Flag
  • Git: Create Aliases for Common Commands to Save Typing

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (934)
  • How to add default value for Entity Framework migrations for DateTime and Bool (830)
  • Get the First and Last Word from a String or Sentence in SQL (822)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (708)

Recent Posts

  • Visual Studio: Pin Variables While Debugging to Track Values Across Sessions
  • C#: Use Target-Typed new Expressions to Reduce Verbosity
  • C#: Use nameof Operator to Avoid Magic Strings
  • C#: Use String Interpolation with Alignment for Formatted Output
  • SQL: Use EXISTS Instead of COUNT for Checking Existence

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com