{"id":682,"date":"2011-12-01T04:05:30","date_gmt":"2011-12-01T04:05:30","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?page_id=682"},"modified":"2014-03-04T05:57:20","modified_gmt":"2014-03-04T05:57:20","slug":"linq-expanded","status":"publish","type":"page","link":"https:\/\/www.ericwhite.com\/blog\/linq-expanded\/","title":{"rendered":"LINQ"},"content":{"rendered":"<h2 style='font-size: small;'><a href='https:\/\/www.ericwhite.com\/blog\/toc-expanded'>Back to TOC<\/a><a style='position: relative; left: 1em;' href='https:\/\/www.ericwhite.com\/blog\/linq-video-expanded'>Just Videos<\/a><span style='position: relative; left: 2em;'><a href='https:\/\/www.ericwhite.com\/blog\/linq-condensed'>Condensed TOC<\/a><\/span><\/h2>\n<p>Language Integrated Query<\/p>\n<ul>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/04\/21\/the-groupadjacent-extension-method.aspx\" target=\"_blank\">The GroupAdjacent Extension Method<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>This post introduces a GroupAdjacent generic extension method that groups elements in a collection with adjacent elements based on a common key.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/07\/10\/how-to-create-hierarchy-from-flat-data-using-linq.aspx\" target=\"_blank\">How to Create Hierarchy from Flat Data using LINQ<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Sometimes you have flat data where there is hierarchy expressed in the data, but the form of the data is flat.  You may need to transform this data into a hierarchy, such as an XML tree.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/07\/24\/are-developers-using-linq.aspx\" target=\"_blank\">Are Developers Using LINQ?<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>I had an interesting conversation with my nephew the other day.  He is a very bright CS student working as a summer intern at a software company (not Microsoft).  He is programming in C# using Visual Studio 2008.  I asked him if developers at his company were using LINQ, and he said, &#8220;No, that the folks in charge had basically forbidden it, because no one understands it.&#8221;  <span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/07\/26\/are-developers-using-linq-part-2.aspx\" target=\"_blank\">Are Developers Using LINQ? (Part 2)<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>There are four basic scenarios where developers use LINQ.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/08\/19\/chunking-a-collection-into-groups-of-three.aspx\" target=\"_blank\">Chunking a Collection into Groups of Three<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Sometimes you need to group a collection into a set of groups, each with n members.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/08\/19\/use-a-lambda-expression-for-an-event-handler.aspx\" target=\"_blank\">Use a Lambda Expression for an Event Handler<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>You can use lambda expressions to write an event handler, even for classes that predate C# 3.0 and the latest version of the framework.  This can shorten your code, and make it easier to read. <span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/08\/19\/find-duplicates-using-linq.aspx\" target=\"_blank\">Find Duplicates using LINQ<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Sometimes you need to find the duplicates in a list.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/09\/12\/closures.aspx\" target=\"_blank\">Closures<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Closures are one of the key components in C# 3.0 that makes functional programming easy, and results in clean syntax.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/09\/30\/linq-to-text-and-linq-to-csv.aspx\" target=\"_blank\">LINQ to TEXT and LINQ to CSV<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>LINQ is a great tool for writing ad-hoc queries and transforms, and occasionally I need to write queries or transforms on text files.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/10\/06\/formatting-linq-code.aspx\" target=\"_blank\">Formatting LINQ Code<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Over time, I&#8217;ve adjusted my code formatting style &#8211; changing the white space that I insert, or where I place the parentheses.  In this post, I detail some aspects of my current code formatting approach, focusing only on formatting LINQ queries that are written in the &#8216;method syntax&#8217;, not using LINQ query expressions (from &#8212; select &#8212;).<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/10\/29\/anders-hejlsberg-introduces-c-4-0-at-pdc-2008.aspx\" target=\"_blank\">Anders Hejlsberg Introduces C# 4.0 at PDC 2008<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Anders Hejlsberg presented a fascinating and entertaining session at PDC 2008 on C# 4.0.  He talked about dynamic typing, optional and named parameters, improved COM interoperability, and improved support for co-variance and contra-variance.  These language improvements are very cool &#8211; they enable us to write code that more closely expresses our intent, with less syntactic noise.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/11\/07\/debugging-linq-queries.aspx\" target=\"_blank\">Debugging LINQ Queries<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Debugging LINQ queries can be problematic.  One of the reasons is that quite often, you write a large query as a single expression, and you can&#8217;t set a breakpoint mid-expression.  Writing large queries in expression context is particularly powerful when using functional construction to form XML (or using the strongly typed DOM in Open XML SDK V2).  This post presents a little trick that makes it easier to use the debugger with LINQ queries that are written using &#8216;method syntax&#8217;.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/11\/14\/the-skiplast-extension-method.aspx\" target=\"_blank\">The SkipLast Extension Method<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>When writing queries, just as you sometimes want to skip the first n items in a collection, on occasion you want to skip the last n items.  You could certain count the items remaining in the collection, and use the Take operator to take all but the last, but this would mean iterating the collection twice, and would result in uglier code.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/04\/08\/why-i-don-t-use-the-foreach-extension-method.aspx\" target=\"_blank\">Why I Don&#8217;t Use the ForEach Extension Method<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>In my first version of my functional programming tutorial, I discussed a ForEach extension method, but I removed the topic from the second version.  I no longer recommend using a ForEach extension method.  This post explains why.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2010\/02\/15\/rollup-extension-method-create-running-totals-using-linq-to-objects.aspx\" target=\"_blank\">Rollup Extension Method: Create Running Totals using LINQ to Objects<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>This post introduces the Rollup extension method, which enables you to write LINQ code to produce a running total.  In addition, it enables you to write the equivalent of a state machine using LINQ and Functional Programming.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2010\/03\/10\/ad-hoc-string-concatenation-using-linq.aspx\" target=\"_blank\">Ad-Hoc String Concatenation using LINQ<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Presents a small idiom to concatenate a set of strings.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2010\/03\/12\/hex-dump-using-linq-in-7-lines-of-code.aspx\" target=\"_blank\">Hex Dump using LINQ (in 7 Lines of Code)<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Presents a bit of LINQ code to do a hex dump of a byte array.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class='ericListItem' href='https:\/\/www.ericwhite.com\/blog\/2011\/02\/11\/simulating-virtual-extension-methods\/' target='_blank'>Simulating Virtual Extension Methods<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Similating virtual extension methods can help in solving problems when dealing with a class hierarchy that uses polymorphism.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class='ericListItem' href='http:\/\/openxmldeveloper.org\/home2\/bm8qcmjy\/public_html\/blog\/b\/openxmldeveloper\/archive\/2011\/11\/16\/screen-cast-functional-programming-utility-methods-and-classes-for-open-xml.aspx' target='_blank'>Screen-Cast: Functional Programming Utility Methods and Classes for Open XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>In the process of developing the PowerTools for Open XML, over the years, I have developed some needed core functionality and utility methods, particularly for writing LINQ to XML code that queries and transforms Open XML documents.<span style='color:#2b91af;'>  (Video)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/powertools-for-open-xml-expanded'>PowerTools for Open XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Back to TOCJust VideosCondensed TOC Language Integrated Query The GroupAdjacent Extension Method This post introduces a GroupAdjacent generic extension method that groups elements in a collection with adjacent elements based on a common key. (Article) Keywords:&nbsp;&nbsp;Functional Programming&nbsp;&nbsp;LINQ&nbsp;&nbsp; How to Create Hierarchy from Flat Data using LINQ Sometimes you have flat data where there is hierarchy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_s2mail":"","footnotes":""},"class_list":["post-682","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/comments?post=682"}],"version-history":[{"count":6,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/682\/revisions"}],"predecessor-version":[{"id":1698,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/682\/revisions\/1698"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}