When LINQ's power really sinks in
|
We spend a lot of time learning the various new technologies such as LINQ, but it still takes a while for them to sink in in a way that we can begin seeing how they fit into the bigger picture. At first we are looking for ways to use the technology. But the tables turn when that technology suddenly lends itself to solve a completely different type of problem that nobody specifically suggested. Patrik Lowendahl had his "aha" moment with LINQ when he used it to solve a very difficult problem. He was trying to compose a type from data that was coming from two different services. Patrik realized that because these lists were both enumerable, he could use link to join them on their common property then project the columns from the two lists into a single type. "This is where I went from loving LINQ to worship it, it just solved an enterprise grade challenge for me with very little and very beautiful code." I remember the first time that I used LINQ to solve a similar problem and realized that I had finally gotten past the basic concepts and had a better understanding it's power, much in the way Patrik has done. In my scenario, I had a set of original data and then another set of the same data with it's current values. I wanted create a set of only the changed data. Happily, my data had a DateTime stamp so it was an easy comparison Before LINQ, I would have had to iterate through the first list, then locate the matching record in the second list, compare the DataTime value and if they were different copy that item to the "changed items" collection. With LINQ I was able to do a join query and spit out the list of changed items with a minimum amount of code. Dim updates = From oc In origCustList Join cc In custlist _ This isn't rocket science, but it was immensely satisfying. It was the first time that LINQ came to my mind for solving a problem as opposed to me looking for a problem to solve with LINQ. |

