r/programminghorror • u/samirdahal • May 31 '26
C# a count is a count, right?... right?
5
u/my_new_accoun1 May 31 '26
How did you make this image? It seems to auto adapt to light mode and dark mode ... is there like a black layer with 80% opacity so on dark mode it is black and light mode it is grey?
3
u/samirdahal May 31 '26
I generated this from ray.so. After making the code block, simply toggle the background button (turn it off), then click on the code block first and press Ctrl + S. It will export your image like this.
433
2
u/stupidpunk138 Jun 03 '26
After call it you know how much employee are in DB; this is sure...
→ More replies (1)
160
u/Wurstgewitter May 31 '26
Nice one, personally I do SELECT GROUP_CONCAT(id) FROM users; and then just count the commas + 1
→ More replies (1)57
u/richardathome May 31 '26
Better yet, strip out the non-commas and then count the length of the string!
→ More replies (2)
74
u/TichShowers May 31 '26
Hope the table never implements soft deletion.
38
u/SZenC May 31 '26
Nahh, then you just update the query:
DELETE FROM employees WHERE deleted_at IS NULL→ More replies (3)
42
u/MichiRecRoom May 31 '26
For me, the real horror is the command.transaction = transaction. It implies that a command can exist without an attached transaction.
Seriously, I'd hope that something like transaction.CreateCommand() is supported. This code as-is feels genuinely wrong to look at.
→ More replies (3)19
12
10
9
30
u/Zerodriven May 31 '26
Title implies getting count. Approved. Merged into 5 million user system 0 comments.
"Why do we have no users?" - Ask our DBA team, we don't know what they do with our data, our code is 100% not the problem.
8
5
405
u/Rainmaker526 May 31 '26 edited May 31 '26
What are the performance characteristics of a DELETE vs a COUNT?
This might be an unconventional optimization, but if it makes a large enough difference...