LINQ-to-XML
What LINQ-to-SQL does for the world of relational database integration, LINQ-to-XML does for the world of XML data access and manipulation. Using the same LINQ-style syntax that works on databases, you can create powerful queries that parse through XML documents and retrieve data in the exact shape you likewhether that shape is in the form of dynamically generated C# classes or simply another XML schema.
LINQ-to-XML includes a new set of XML-related classes such as XDocument, XElement, and XAttribute. The beauty of these classes is that their constructors take instances of applicable child classes. This lets you create elements on-the-fly in a nested constructor format like this:
XElement newElement = new XElement( "data", new XAttribute("value", "12"));
This creates an element that looks like:
<data value="12"/>
This is a more intuitive and easy-to-use syntax than the existing DOM classes in the .NET Framework when you are specifically dealing with dynamic query and production of XML data. In the Moniqer project, we used LINQ-to-XML to dynamically create RSS feeds from the output of LINQ-to-SQL queries in the same line of code. When the code itself becomes a thing of beauty, you know you're on the right path. Listing Three, for instance, takes bookmarks contained in the bookmarkList parameter, which is of type IQueryable<BookmarkResults> and wraps that in a custom-built XML package that is in a format readable by most RSS readers.
Response.ContentType = "text/xml"; XElement rssRoot = new XElement("rss", new XAttribute("version", "2.0"), new XElement("channel", new XElement("title", feedTitle), new XElement("link", "http://[my server]/moniqer/default.aspx/"), new XElement("description", feedDescription), new XElement("ttl", "360"), from bookMark in bookmarkList.Take(rowLimit) select new XElement("item", new XElement("title", bookMark.Bookmark.Title), new XElement("link", bookMark.Bookmark.Address), new XElement("pubDate", bookMark.Tags.Last(). CreatedOn.ToString()+ " GMT"), new XElement("Creator", bookMark.Tags.Last().UserID), new XElement("author", bookMark.Tags.Last().UserID), new XElement("description", bookMark.Bookmark.Description), from tag in bookMark.Tags select new XElement("category", tag.Title))); Response.Write(rssRoot.ToString()); Response.End();
The Future of ADO.NET
ADO.NET's future is tied to ADO.NET vNext, which uses LINQ to support the ADO.NET Entity Frameworkan abstraction model that lets you define an entity model in an XML file. Underneath that there is a schema definition XML file that corresponds directly to the table structure in your database. There is also a mapping file that relates the Entity Model with the physical schema. This abstraction and loose coupling provides an amazing framework that supports things like Entity Inheritance and Entity Composition (creating a single C# object class/entity that reads and writes from multiple tables). From what I can tell, the ADO.NET team has done a great job of taking the best ideas that drove ObjectSpaces, WinFS, and LINQ-to-SQL and honing them into what I think is a glimpse at the future of data access for enterprise applications.
The Future of Moniqer
The current version of Moniqer resides on CodePlex (www.codeplex.com/Wiki/View .aspx?ProjectName=Moniqer). We are working on rewriting the Moniqer data tier in the Entity Framework to provide the rich scalability, flexibility, and performance for our enterprise applications. Once that is complete, we can easily add schema-changing features such as support for named groups and scoping of bookmarks, tag blending (monitoring someone else's tag within your own), discussions revolving around individual bookmarks, and more.
In short, following CSS design patterns using the ASP.NET web application framework and backing that framework with SQL Server 2005 and LINQ-to-SQL provides you with a powerful foundation on which to build enterprise social bookmarking and similar applications. If you are planning on building a data-driven application with ASP.NET, take a look at LINQ-to-SQL and ADO.NET vNext and check out the source code for Moniqer.