Following on from the recent discussion about the merits or otherwise of LINQ, I came across some more nice examples of how neat it is today whilst solving some coding problems. The code is in C# as I'm not confident that I'd get it correct in X#, but of course one of the advantages of X# is that basically if you can do it in C# you can do it in X# too.
The examples suppose we have a list of Order objects, each of which also has a property OrderItems which contain the list of items within each order.
Example 1 - find the order which contains the orderitem ID==10.
These nice simple examples of LINQ Extension Methods in action got me to look much more closely (in detail) into their use, and to make some other examples in X# syntax.
To wet guys appetites for these samples, here is a nice X# example of the 'let' clause in a query syntax line.
The let gives us a way to specify a variable in out query code line, and then re-use it. I have also used a static method or two in this code - we may need to be careful in using Methods in query LINQ code for L2S and L2E as the code needs to be able to be expressed in T-SQL script, so we can't just use any old .NET function/method.
More fun in the morning, first here are the 'let' images :-