My girlfriend asked why I always cursed at LINQ
-
So I gave her a grocery list in LINQ ```cs var query_where1 = ( from item in Grocery.Store where item.Price < 1.99 where item.Fresh == true where item.Type.Contains("Produce") select item).Take(5); ``` Which she really didn't care for; and I followed up with it in SQL ```sql SELECT TOP 5 * FROM Grocery.Store WHERE Price < 1.99 AND Fresh = 1 AND Type = 'Produce' ``` I think she understands now
MadMyche wrote:
I think she understands now
or:
(select bacon).take(all)
;P MarcLatest Article - Merkle Trees Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
MadMyche wrote:
I think she understands now
or:
(select bacon).take(all)
;P MarcLatest Article - Merkle Trees Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
So I gave her a grocery list in LINQ ```cs var query_where1 = ( from item in Grocery.Store where item.Price < 1.99 where item.Fresh == true where item.Type.Contains("Produce") select item).Take(5); ``` Which she really didn't care for; and I followed up with it in SQL ```sql SELECT TOP 5 * FROM Grocery.Store WHERE Price < 1.99 AND Fresh = 1 AND Type = 'Produce' ``` I think she understands now
-
So I gave her a grocery list in LINQ ```cs var query_where1 = ( from item in Grocery.Store where item.Price < 1.99 where item.Fresh == true where item.Type.Contains("Produce") select item).Take(5); ``` Which she really didn't care for; and I followed up with it in SQL ```sql SELECT TOP 5 * FROM Grocery.Store WHERE Price < 1.99 AND Fresh = 1 AND Type = 'Produce' ``` I think she understands now
-
I hardly ever need to. Sometimes a I need an IN, but rarely an OR. And I'm not saying remove AND and OR, just make any additional WHEREs act as ANDs.
When I'm testing out filters I'm usually starting with
WHERE 1=1
and add all conditions with an AND. But I can see what you're getting at. <edit>Just as you answered to Madmyche</edit>Wrong is evil and must be defeated. - Jeff Ello
-
So I gave her a grocery list in LINQ ```cs var query_where1 = ( from item in Grocery.Store where item.Price < 1.99 where item.Fresh == true where item.Type.Contains("Produce") select item).Take(5); ``` Which she really didn't care for; and I followed up with it in SQL ```sql SELECT TOP 5 * FROM Grocery.Store WHERE Price < 1.99 AND Fresh = 1 AND Type = 'Produce' ``` I think she understands now
Looks to me just a simple matter of different syntax. One does not appear to be any more succinct or easier to read than the other.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
So I gave her a grocery list in LINQ ```cs var query_where1 = ( from item in Grocery.Store where item.Price < 1.99 where item.Fresh == true where item.Type.Contains("Produce") select item).Take(5); ``` Which she really didn't care for; and I followed up with it in SQL ```sql SELECT TOP 5 * FROM Grocery.Store WHERE Price < 1.99 AND Fresh = 1 AND Type = 'Produce' ``` I think she understands now
Don't use that convoluted Linq syntax and instead just use the static methods. Code looks way cleaner that way.
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
-
I know what you mean, I prefer to use the Linq methods as well - the Linq syntax is just a PITA to read.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
+1 :thumbsup:
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
-
Looks to me just a simple matter of different syntax. One does not appear to be any more succinct or easier to read than the other.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
DavidCrow wrote:
One does not appear to be any more succinct
One appears blatantly more succinct. Swap the simple example for a real query and you'll be seeing complete proza.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
So I gave her a grocery list in LINQ ```cs var query_where1 = ( from item in Grocery.Store where item.Price < 1.99 where item.Fresh == true where item.Type.Contains("Produce") select item).Take(5); ``` Which she really didn't care for; and I followed up with it in SQL ```sql SELECT TOP 5 * FROM Grocery.Store WHERE Price < 1.99 AND Fresh = 1 AND Type = 'Produce' ``` I think she understands now
Why
Type = 'Produce'
becameitem.Type.Contains("Produce")
? Shouldn't it becomeitem.Type == "Produce"
?