<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>You had me at "Hello World" : LINQ</title><link>http://blogs.msdn.com/helloworld/archive/tags/LINQ/default.aspx</link><description>Tags: LINQ</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to Find Out Which Column Caused SSIS to Fail?</title><link>http://blogs.msdn.com/helloworld/archive/2008/08/01/how-to-find-out-which-column-caused-ssis-to-fail.aspx</link><pubDate>Fri, 01 Aug 2008 15:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8792905</guid><dc:creator>HelloWorld</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/helloworld/comments/8792905.aspx</comments><wfw:commentRss>http://blogs.msdn.com/helloworld/commentrss.aspx?PostID=8792905</wfw:commentRss><description>&lt;P&gt;In my previous &lt;A href="http://blogs.msdn.com/helloworld/archive/2008/07/25/how-to-decipher-understand-ssis-error-code.aspx" mce_href="http://blogs.msdn.com/helloworld/archive/2008/07/25/how-to-decipher-understand-ssis-error-code.aspx"&gt;post&lt;/A&gt;, I explained how you can find out the error description for the error id that is returned by SSIS.&lt;/P&gt;
&lt;P&gt;Of course, that information is only half helpful, debugging the issue also involve knowing which column caused that error. The Error Column returns an integer value which is also a little bit confusing, how can I know which column is represented by this integer value?&lt;/P&gt;
&lt;P&gt;The Error Column corresponds to the value of the lineageId attribute inside the SSIS package. As you already know, SSIS package is an xml file. The node that contains lineageId attribute may or may not has a name attribute. The value of the name attribute is the column name.&lt;/P&gt;
&lt;P&gt;To query the lineage id and the column id, you can use this code using LINQ.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;private &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Dictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt; GetLineageIdAndColumnMapping(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;SSISFilename)
{
    &lt;SPAN style="COLOR: #2b91af"&gt;XDocument &lt;/SPAN&gt;xdoc = &lt;SPAN style="COLOR: #2b91af"&gt;XDocument&lt;/SPAN&gt;.Load(SSISFilename);
    &lt;SPAN style="COLOR: #2b91af"&gt;Dictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt; LineageColumn = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Dictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt;();

    &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;LineageNodes = &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;Nodes &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;xdoc.Descendants()
                       &lt;SPAN style="COLOR: blue"&gt;where &lt;/SPAN&gt;Nodes.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"lineageId"&lt;/SPAN&gt;) != &lt;SPAN style="COLOR: blue"&gt;null &lt;/SPAN&gt;&amp;amp;&amp;amp;
                             Nodes.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"lineageId"&lt;/SPAN&gt;).Value != &lt;SPAN style="COLOR: #2b91af"&gt;String&lt;/SPAN&gt;.Empty &amp;amp;&amp;amp;
                             Nodes.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"name"&lt;/SPAN&gt;) != &lt;SPAN style="COLOR: blue"&gt;null &lt;/SPAN&gt;&amp;amp;&amp;amp;
                             Nodes.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"name"&lt;/SPAN&gt;).Value != &lt;SPAN style="COLOR: #2b91af"&gt;String&lt;/SPAN&gt;.Empty
                       &lt;SPAN style="COLOR: blue"&gt;select new
                       &lt;/SPAN&gt;{
                           LineageId = &lt;SPAN style="COLOR: #2b91af"&gt;Convert&lt;/SPAN&gt;.ToInt64(Nodes.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"lineageId"&lt;/SPAN&gt;).Value),
                           ColumnName = Nodes.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"name"&lt;/SPAN&gt;).Value
                       };

    &lt;SPAN style="COLOR: blue"&gt;foreach &lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;Item &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;LineageNodes)
        LineageColumn.Add(Item.LineageId, Item.ColumnName);

    &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;LineageColumn;
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;If you are not using .Net framework 3.5, then this XPath code will also do the trick.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;private &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Dictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt; GetLineageIdAndColumnMapping(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;SSISFilename)
{
    &lt;SPAN style="COLOR: #2b91af"&gt;XmlDocument &lt;/SPAN&gt;doc = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlDocument&lt;/SPAN&gt;();
    doc.Load(SSISFilename);
    &lt;SPAN style="COLOR: #2b91af"&gt;Dictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt; LineageColumn = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Dictionary&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;long&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt;();

    &lt;SPAN style="COLOR: blue"&gt;foreach &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;XmlNode &lt;/SPAN&gt;node &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;doc.SelectNodes(&lt;SPAN style="COLOR: #a31515"&gt;"//*[@lineageId != '' and @name != '']"&lt;/SPAN&gt;))
        LineageColumn.Add(&lt;SPAN style="COLOR: #2b91af"&gt;Convert&lt;/SPAN&gt;.ToInt64(node.Attributes[&lt;SPAN style="COLOR: #a31515"&gt;"lineageId"&lt;/SPAN&gt;].Value),
                          node.Attributes[&lt;SPAN style="COLOR: #a31515"&gt;"name"&lt;/SPAN&gt;].Value);
    

    &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;LineageColumn;
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;That code above, will give a dictionary of lineage id and the actual column name, now using the value from the ErrorColumn field, you can lookup the actual column name.&lt;/P&gt;
&lt;P&gt;Someone might say, the XPath is shorter, it is better. Well, there are more than one metrics to evaluate a piece of code. LINQ enables code reviewer who are not familiar with XPath to quickly review the code, understand what is going on, and comment on it.&lt;/P&gt;
&lt;P&gt;The beauty of LINQ, your knowledge is almost transferable among different data sources.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8792905" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/helloworld/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/How+to/default.aspx">How to</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/Database/default.aspx">Database</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/SSIS/default.aspx">SSIS</category></item><item><title>How to Convert a list of Object/String to an Array Using LINQ?</title><link>http://blogs.msdn.com/helloworld/archive/2008/03/19/how-to-convert-a-list-of-object-string-to-an-array-using-linq.aspx</link><pubDate>Wed, 19 Mar 2008 02:05:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8324143</guid><dc:creator>HelloWorld</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/helloworld/comments/8324143.aspx</comments><wfw:commentRss>http://blogs.msdn.com/helloworld/commentrss.aspx?PostID=8324143</wfw:commentRss><description>&lt;p&gt;This is something that I really like, I can convert a list of objects into an array of something.&lt;/p&gt;  &lt;p&gt;I had a need to convert a list of string into an array of string, of course it can be done easily in several different ways, creating an array of int, converting the string element, and populate the int array, or using List&amp;lt;int&amp;gt; as container.&lt;/p&gt;  &lt;p&gt;Using LINQ, is very simple.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] Origin = &lt;span style="color: blue"&gt;new string&lt;/span&gt;[] { &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;2&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;4&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;5&amp;quot; &lt;/span&gt;};
&lt;span style="color: blue"&gt;int&lt;/span&gt;[] Result = Origin.Select(item =&amp;gt; &lt;span style="color: #2b91af"&gt;Convert&lt;/span&gt;.ToInt32(item)).ToArray();&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Less code to write. :)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8324143" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/helloworld/archive/tags/.Net+Framework/default.aspx">.Net Framework</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/How+to/default.aspx">How to</category></item><item><title>I Am in Love with LINQ</title><link>http://blogs.msdn.com/helloworld/archive/2008/03/16/why-you-will-fall-in-love-with-linq.aspx</link><pubDate>Sun, 16 Mar 2008 20:47:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8269756</guid><dc:creator>HelloWorld</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/helloworld/comments/8269756.aspx</comments><wfw:commentRss>http://blogs.msdn.com/helloworld/commentrss.aspx?PostID=8269756</wfw:commentRss><description>&lt;p&gt;I have been reviewing LINQ since last year, but I had never had a chance to actually jump and use it extensively. My last project uses Visual Studio 2008, and there are opportunities to use LINQ.&lt;/p&gt;  &lt;p&gt;Probably because I have reviewed it before, the learning curve was not that steep. I use LINQ to SQL and LINQ to XML, and I love it. Prior to use LINQ, I had to open my XPath reference book when I was dealing with XML and XSLT. Now, I don't really have to deal with the plumbing, and let LINQ does it for me. It increases my productivity. Troubleshooting is much more straightforward.&lt;/p&gt;  &lt;p&gt;LINQ to XML does not replace the flexibility of XPATH and XSLT. I still like the level of control and flexibility that XSLT and XPATH provides, but for most of the time, LINQ to XML serves my need.&lt;/p&gt;  &lt;p&gt;So, if you are using Visual Studio 2008, I encourage you to check it out.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8269756" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/helloworld/archive/tags/xml/default.aspx">xml</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/LINQ/default.aspx">LINQ</category></item><item><title>Free Microsoft Press e-books (LINQ, ASP.Net AJAX, Silverlight)</title><link>http://blogs.msdn.com/helloworld/archive/2008/01/03/free-microsoft-press-e-books-linq-asp-net-ajax-silverlight.aspx</link><pubDate>Thu, 03 Jan 2008 20:56:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6970230</guid><dc:creator>HelloWorld</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/helloworld/comments/6970230.aspx</comments><wfw:commentRss>http://blogs.msdn.com/helloworld/commentrss.aspx?PostID=6970230</wfw:commentRss><description>&lt;p&gt;Microsoft is offering free e-books from Microsoft Press. The subjects that I have seen, LINQ, ASP.Net AJAX, and Silverlight 1.0. All of these are introduction e-books. Those are new cool technologies.&lt;/p&gt;  &lt;p&gt;I would like to encourage you to take advantage of this free e-books &lt;a href="http://www.microsoft.com/learning/vstudio/2008/default.mspx#EBOOK"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6970230" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/helloworld/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/ASP.Net/default.aspx">ASP.Net</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/.Net+Framework/default.aspx">.Net Framework</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/Silverlight/default.aspx">Silverlight</category></item></channel></rss>