Some wicked cool use of LINQ
|
LINQ is definitely one of those "the more you know, the less you know" topics. I'm looking at a blog post written by Jim Wooley where he is first queries an xml file in a way that the resulting type structure matches the structure of a LINQ to SQL type and therefore is able to add the results into LINQ to SQL objects with one swift command: LINQtoSQLDataContext.MyItems.AddAll(from foo in myXMLDocument... (Note that AddAll becomes InsertAllonSubmit with VS2008 RTM) That's cool. Often when we learn technologies we do so in a bit of a vacuum: learning Linq to SQL and learning LINQ to XML but not thinking of combining the two. It was this kind of thinking (actually watching a screencast that Jim did earlier this year) that inspired me a few months ago to do LINQ queries over disparate types (referred to as heterogeneous queries) and combine them all using LINQ. My example was to query Outlook email messages, Outlook contact info and SQL Server data to combine data from all three (using joins) into one meaningful set of results. Here's a blog post I wrote about that. Now the XML document that Jim was working with happened to be an RSS Feed from his blog. And Jim goes yet another step. He discovered the SyndicationFeed class that is part of WCF and populates that with his RSS feed. The SyndicationFeed is a strongly typed class that represents an RSS feed or an ATOM feed. Rather than using the XML Document and LINQ to XML, he can then query of over the collection of feed items in a strongly typed way and use the results of that to populate the blog. Not to say that he couldn't use intellisense with LINQ to XML - this is possible if you create in advance a schema representing the structure of the XML file that you wish to query. VB has a nice tool for doing this "XML to Schema". Overall, I seem to be learning LINQ in fits and starts. The only downside of this nice alternative for querying the RSS feed is that I can't use it in my example of working with LINQ to XML, or the LINQ to XML part of the demo will disappear! |


Comments (1)
If you can't use the example of working with LINQ to XML with the SyndicationFeed, I guess you're just going to have to come up with some other new super cool LINQ to XML demo... Shouldn't be too hard since VB 9's XML literals are so cool by themselves. ;-)
Posted by Jim Wooley | November 29, 2007 3:31 PM