Monday, January 21, 2008
After many, many, many long months of work, LINQ in Action is finally done!  Fabrice, Jim, and I are very proud of the final product and really hope you enjoy it.  We've already heard a lot of positive feedback from those who purchased the Early Access Preview from Manning, and are hopefull that LINQ in Action will be a valuable resource for everyone who is trying to add LINQ to their development toolbox.  My favorite quote thus far is from Ben Hayat on the LINQ in Action forums where he said "I had gotten other books on Linq, and this book is simply the BEST!".  Now for those of you who don't know Ben, it should be very clear that he's extremely smart and intelligent and you should believe everything he says, especially when it comes to what the best LINQ book is! :D 

Since the book is on the printers as we speak, it isn't yet available on Amazon for immediate shipping, however, I've been told it should make it's way over there in the next couple of weeks.  Given that, now is a great time to head over and pre-order it!  If you want the book sooner rather than later the best way to get it is directly via Manning's website.

To keep updated on the status of the book, including errata, code samples, or to ask Fabrice, Jim, or I any questions about our LINQ book you should drop by the LINQ in Action website or the author forums on the Manning website.

Monday, January 21, 2008 2:32:52 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [3]  |  Trackback
 Wednesday, September 12, 2007
Over the last year I've spent a lot of my "free" time with LINQ.  When not writing and/or experimenting with LINQ I've been trying to learn Ruby.  Since I'm primarily a Microsoft guy, I've spent time in some Microsoft "friendly" Ruby communities such as SoftiesOnRails. As I think is typical in most passionate technology oriented communities, most Ruby peeps aren't real big fans of Microsoft.  I've heard numerous people in the Ruby community discount all things Microsoft, which led me to wonder if any Rubyists would ever give LINQ a fair look.  A couple weeks ago I came across Chris' "Full of Ambition" post on the err the blog site.  As soon as I saw ambition, I thought to myself "hey, it's LINQ for Ruby".  From reading over the initial post, it didn't sound like the guys behind ambition where inspired by LINQ at all, but instead were gunning for Rack.  A noble ambition, but surely LINQ would be a better and more ambitious goal!  Well it turns out that since their initial post the gents behind ambition have found LINQ, and set it as their new target!  In their most recent post about ambition they state:
We’ve moved our sights from Rack to LINQ. That is, we don’t want to only support other ORMs—we want Ambition to be a query language for SQL, LDAP, XPath, the works. The 1.0 release will be backend-agnostic. Maybe then we’ll change the name to Hubris? Time will tell.
As a big fan of both LINQ and Ruby I'm glad to see some LINQ'ness finding it's way into Ruby. 

Links:
Intro to Ambition
Update to Ambition, with LINQ as the new target
 | 
Wednesday, September 12, 2007 5:27:04 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Thursday, August 30, 2007
A while back I posted an example of how to convert a comma seperated file (CSV) to XML using LINQ to XML and functional construction.  We're in the final push to get LINQ in Action to production and as such I've been spending a lot of time going back through the chapters cleaning things up, as well as making sure both a C# and VB.NET example is provided for every code sample presented in the book.  Tonight I was converting a code sample from Chapter 12 that shows how to convert a CSV file to XML using LINQ to XML.  While the C# code is very nice, I like the VB version that is shown below even better.

Imports System.IO
Imports System.Xml.Linq

Module FlatFileToXmlWithXmlLiterals
  Sub Main()
    Dim xml As XElement = <books>
                          <%= From line In File.ReadAllLines("books.txt") _
                          Where Not line.StartsWith("#") _
                          Let items = line.Split(",") _
                          Select _
                          <book>
                            <title><%= items(1) %></title>
                            <authors>
                              <%= From authorFullName In items(2).Split(";") _
                                Let authorNameParts = authorFullName.Split(" ") _
                                Select <author>
                                         <firstName><%= authorNameParts(0) %></firstName>
                                         <lastName><%= authorNameParts(1) %></lastName>
                                       </author> _
                              %>
                            </authors>
                            <publisher><%= items(3) %></publisher>
                            <publicationDate><%= items(4) %></publicationDate>
                            <price><%= items(5) %></price>
                            <isbn><%= items(0) %></isbn>
                          </book> _
                        %>
                      </books>

    Console.WriteLine(xml)
  End Sub
End Module

As an aside, if you've been meaning to learn about LINQ, or if you've already begun your journey, now is a great time to checkout the early access edition of LINQ in Action.  We have every chapter available for download, and will very shortly be making the source code available.  We still have a little ways to go, but we're getting close!

Download the sample project here: Chapter12.FlatFileToXml.Vb.zip (10.09 KB)
Friday, August 31, 2007 1:26:49 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Thursday, August 02, 2007
While working on our LINQ book I've come to really enjoy LINQ to XML. I've worked with a lot of XML API's over the years, however, the LINQ to XML API is my favorite...by far. In addition to providing all the nice query facilities made available by LINQ, it also provides a lot of other great features that many people overlook. As I promised long ago, I'm going to begin to talk about the things that I enjoy about LINQ to XML in hopes that it will help you realize that the red headed step child of LINQ has some things to offer the world as well. :)

One of the most common things that we need to do when dealing with XML is transform it. We're usually transforming it into an alternate XML format, or transforming the XML into a set of objects. In this post I'm going to quickly look at some of the transformation capabilities offered by LINQ to XML. To help us get started I'm going to use the following XML which is the XML representation of a contact in Highrise.

<?xml version="1.0" encoding="UTF-8"?>
<person>
  <author-id type="integer">1436</author-id>
  <background/>
  <company-id type="integer">1226900</company-id>
  <created-at type="datetime">2007-06-09T03:13:15Z</created-at>
  <first-name>Steve</first-name>
  <group-id type="integer"/>
  <id type="integer">1226899</id>
  <last-name>Eichert</last-name>
  <owner-id type="integer"/>
  <title/>
  <updated-at type="datetime">2007-06-09T03:15:16Z</updated-at>
  <visible-to>Everyone</visible-to>
  <contact-data>
    <email-addresses type="array">
      <email-address>
        <address>steve.eichert at google mail dot com</address>
        <id type="integer">559722</id>
        <location>Work</location>
      </email-address>
    </email-addresses>
    <web-addresses type="array">
      <web-address>
        <id type="integer">942962</id>
        <location>Work</location>
        <url>http://iqueryable.com/</url>
      </web-address>
    </web-addresses>
  </contact-data>
</person>

Rather than be stuck with our contact in XML, let's see what we can do to transform the above XML into the hCard microformat. We're going to ignore a bunch of data, such as all the ids, since it doesn't have any meaning outside of Highrise. When we're done we'll end up with the much simplified XML shown below:

<div class="vcard">
  <div class="fn">Steve Eichert</div>
  <div>Email: <span class="email">steve.eichert at google mail dot com</span></div>
  <a class="url" href="http://iqueryable.com/">http://iqueryable.com/</a>
</div>

The first step for transforming our Highrise XML into the hCard microformat is to load the Highrise XML into an XElement.

XElement highriseRoot = XElement.Load("highrise-contact.xml");

We use the static Load method of XElement to load the XML contained within the "highrise-contact.xml" file that we've saved locally. I don't believe the Highrise API is officially supported at the moment so I'm not going to load the contact details directly from the highrisehq.com site. Perhaps, in a future post we can explore that as an option.

Anywho, once our XML is loaded into an XElement, we can transform our Highrise XML into the hCard microformat by building a new XElement. We'll use the Element query axis method to retrieve the first and last name of the contact, and we'll embed query expressions and make use of the Descendants query axis method for selecting all the email and web addresses for the contact within the source XML. When we put it all together we end up with the C# code below:

XElement highriseRoot = XElement.Load("highrise-contact.xml");

XElement hCard =
    new XElement("div",
        new XAttribute("class", "vcard"),
        new XElement("div",
            new XAttribute("class", "fn"),
            highriseRoot.Element("first-name") + " " + highriseRoot.Element("last-name")
        ),
        from emailElement in highriseRoot.Descendants("email-address")
        select new XElement("div",
            "Email:",
            new XElement("span",
                new XAttribute("class", "email"),
                (string) emailElement.Element("address")
            )
        ),
        from webElement in highriseRoot.Descendants("web-address")
        select
        new XElement("a",
            new XAttribute("class", "url"),
            new XAttribute("href", (string) webElement.Element("url")),
            (string) webElement.Element("url")
        )
    );

Console.WriteLine(hCard);

At first glance, the above code might be overwhelming. However, once you come to understand the power of functional construction you'll quickly realize how wonderful LINQ to XML can be for transforming XML to alternate XML formats. In addition to making it easy to transform XML into alternate XML formats, LINQ to XML also makes it very easy to transform XML into objects. If we have a Contact class defined as:

public class Contact {
    public string Name { get; set; }
    public IEnumerable<string> EmailAddresses { get; set; }
    public IEnumerable<string> Urls { get; set; }
}

We can transform the contact details in our XML into a Contact instance with the following code:

Contact contact = new Contact {
    Name = (string) highriseRoot.Element("first-name") + " " + (string) highriseRoot.Element("last-name"),
    EmailAddresses = highriseRoot.Descendants("email-address").Select(e => (string)e.Element("address")),
    Urls = highriseRoot.Descendants("web-address").Select(e => (string)e.Element("url"))
};

After looking back at the sample here I wish I had chosen an XML fragment with a little more hierarchy, however it's much too late for that now. Hopefully, the code included in this post gives you a small taste of the types of XML transformations possible with LINQ to XML. As you begin to work with LINQ to XML, you'll find that functional construction, combined with query axis methods, and query expressions provide a tremendous amount of flexibility for transforming XML. Additionally, the new object initializer syntax and LINQ to XML's ability to easily construct objects from XML makes it very easy to create objects from XML. I've attached a zip file with the code above to this post. (VS2008 Beta 2 Required) LINQtoXMLTransformSample.zip (23.69 KB)

Friday, August 03, 2007 3:20:02 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, June 01, 2007
Matt Warren, who has been one of the lead developers on many aspects of LINQ, recently posted two very interesting stories describing The Origins of LINQ to SQL, and IQueryable's Deep Dark Secret.  In his first post on the Origins of LINQ to SQL, Matt talks about some of the previous dead projects, such as ObjectSpaces and WinFS, that influenced LINQ to SQL.  I found it interesting to hear about how LINQ to SQL came to be, and some of the internal politics that had to be overcome to make it a reality.  In his second post, IQueryable's Deep Dark Secret, Matt talks about how a call from Don Box eventually led to what is now at the core of LINQ, IQueryable.

Saturday, June 02, 2007 12:38:52 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, May 16, 2007
Mike Champion has a great post that offers up some theories for why LINQ to XML has been getting positive user reviews.  In short, he thinks it could be because Anders is "the man", and can read every developers mind.  He also has a magical crystal ball that he can look into to figure out what to include and more importantly what to exclude from the LINQ to XML API.  I might not be getting all the details of Mike's post right, so you *may* want to read what he said yourself rather than taking my word for it.

I've been working with LINQ to XML as part of my work on our LINQ book, and I must say it's a seriously kick ass XML API.  I've done a lot of XML work in the past and I've never had as much fun working with XML as I do when using LINQ to XML.  The key highlights for me are:
  • Functional Construction: Have you ever created XML using existing .NET XML API's?  Enough said, functional construction beats the pants out of anything else out there for creating XML.
  • Powerful Transformation capabilities: By combining the powerful querying capabilities of LINQ with the functional construction pattern for XML creation LINQ to XML provides a lot of really nice transformation capabilities.  In addition to supporting superb XML to XML transformations, we also get killer support for transforming our XML into object structures, LINQ to SQL objects, and whatever else you can think up.
  • LINQ: What else needs to be said, sprinkling LINQ query support on top of an XML API makes for a kick ass query experience.  We get the best of XPath and XQuery but in a much nicer, cleaner, and straightforward API.
Now that I'm back on the "blogging wagon" I'll be looking to start the LINQ to XML for president campaign that I promised way back when.

Wednesday, May 16, 2007 12:14:55 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Sunday, April 15, 2007
Mohammed Hossam El-Din has created an implementation of IQueryable that enables LINQ to be used against Flickr.  The LINQ to Flickr implementation leverages the Flickr.NET library.  I've been wanting to write my own implementation of IQueryable but it looks like everyone is beating me to all the good data sources. :)  Hopefully, once I finish my chapters for the LINQ book I'll have a chance to complete an implementation of IQueryable for an interesting data source...if there are any left  :)

Monday, April 16, 2007 2:06:46 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Thursday, April 05, 2007
If you're an NHibernate user, and/or interesting in learning about how you can create custom implementations of LINQ using IQueryable, I strongly urge you to checkout what Ayende and Bobby Diaz (and others?) have been up to with LINQ to NHibernate.

Here are some of my favorite posts thus far:

Thursday, April 05, 2007 12:44:09 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, March 07, 2007
I'm going to document the things I run into as I transition from the May 2006 CTP of LINQ to the full March 2007 CTP of Orcas. Tonight after sorting out my data source issue I ran into a compile error with my Visual Basic code samples that are using XML Axis properties. The error is "XML Axis properties do not support late binding". Hopefully I'll be able to post back here shortly with an answer to why I'm getting this....

UPDATE:  Thanks to a comment from Avner I figured out that this is due to a regression in the capability of VB9 to infer types.  Previously things worked swimmingly with the following code:

    Dim rss = XElement.Load("rss.xml")
    Dim items = rss...<item>

With the March CTP the type of "rss" needs to be explicitly defined like so:

    Dim rss As XElement = XElement.Load("rss.xml")
    Dim items = rss...<item>

I like the old way better :)


 |  |  | 
Thursday, March 08, 2007 3:00:27 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Tuesday, March 06, 2007
Yesterday I mentioned I was having some trouble adding a Data Source in Orcas. I'm happy to report that following the instructions in the Orcas March CTP on Vista Database Connections Problem Solved post resolved my issue. Once I commented out the SQL Server CE Data Provider in the machine.config everything was back to normal.
 |  | 
Wednesday, March 07, 2007 2:08:35 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, March 05, 2007
There has been a lot of talk about LINQ as well as LINQ to SQL.  People seem to be genuinely interested in what they're going to offer.  LINQ to XML on the other hand doesn't seem to be getting much love.  I for one think it deserves it.  In the coming weeks I'm going to start a marketing campaign for LINQ to XML that will aim to convince you that LINQ to XML deserves some love as well.  Before getting started, let me ask the question, why aren't you giving LINQ to XML any love? 

Tuesday, March 06, 2007 3:25:18 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [3]  |  Trackback
I had a jolly good fun time tonight updating my code samples to the March CTP of Orcas.  Well, actually, I'm not quite finished as of yet because of the wonderful error in the title of this post.  It appears VS.NET Orcas doesn't want to let me recreate my data connection for my database that I'm using for some LINQ to SQL examples. Woot!  Hopefully I'll figure out what the dealy is shortly because I've got chapters I need to finish. :)

Tuesday, March 06, 2007 3:20:47 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Friday, February 16, 2007
I'm with Mike, C# 3.0 needs the Visual Basic 9 XML Syntax.  Maybe "needs" is a strong word, since the functional construction model used for building XML with LINQ to XML is head and shoulders above what we have available in today's XML API's, but it sure would be nice!  Since the VB guys already have it done it should be a piece of cake to move over.  Those Microsoft guys have mad skills, I expect it to be in the next CTP! :)

Friday, February 16, 2007 1:36:33 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [9]  |  Trackback
 Sunday, February 11, 2007
Over on the XML Team's blog, Avner outlines some VB 9.0 XML changes that will be showing up in the February CTP.   As I've mentioned in the past VB 9's XML features are very compelling, so much so that they have me wanting to write code in VB which I haven't done since I started working with .NET.  The major changes in the February CTP include:

  • Attribute axis property is string
  • Global Xml namespace syntax has changed
  • Added auto-completion
  • Xml names are VB symbols
  • Improved error handling
For the full details checkout Avner's VB 9.0 Xml in Visual Studio "Orcas" February CTP post.

 |  | 
Sunday, February 11, 2007 7:24:44 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, February 02, 2007

The LINQ videos seem to be rolling out lately. 

Friday, February 02, 2007 2:29:59 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback

Boooooooooooooo! :)  I'd really like to get a new release that includes everything LINQ related that we saw in the May 2006 CTP so I can start updating all my code samples and use all the new wizz bang features that I'm sure they've added.

Update: I think I misread the post above.  The next Orcas CTP isn't being pushed to March, it's just a bunch of LINQ to SQL stuff that isn't making it into February that will show it's face in March.

 | 
Friday, February 02, 2007 2:14:43 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Thursday, February 01, 2007
I can't wait for the next CTP of Orcas to drop since it supposed to have feature parity with the ancient May 2006 LINQ Preview I'm still using.

  • Mike has a nice post where he looks to Deconstruct LINQ.  I often find posts like Mike's, where the author is letting what they've learned flow out in a post, the most beneficial.
  • Alex is considering a couple implementations of IQueryable, which he is calling LINQ to Web, that sound very useful.  I've been thinking about writing an implementation of LINQ to Google or LINQ to Live Search myself.  I have a feeling that a bunch of what Alex is after in LINQ to DOM could be handled with a couple extensions on top of LINQ to XML.
  • There is a new video on Channel 9 with Anders Hejlsberg, Herb Sutter, Erik Meijer, Brian Beckman that is bound to be full of interesting topics.  I've been having some iPod video troubles lately and can't seem to find a good WMV to iPod Video Converter that runs on a Mac.  I should probably just do the video conversion in Parallels...ok started...can't wait to check it out.

Friday, February 02, 2007 4:12:14 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [1]  |  Trackback