Book Image

LINQ Quickly

By : N Satheesh Kumar
Book Image

LINQ Quickly

By: N Satheesh Kumar

Overview of this book

<p>This book gets you started with LINQ and shows how it will make your programming life easier by making use of new features from the .NET Framework 3.0. This book is split into seven chapters, each of which is dedicated to presenting a feature of LINQ and its usage in real-life scenarios. <br /><br />Language Integrated Query (LINQ) is a new feature in Visual Studio 2008 that extends its query capabilities, using C# and Visual Basic. Visual Studio 2008 comes with<br />LINQ provider assemblies that enable the use of LINQ with data sources such as in-memory collections, SQL relational databases, ADO.NET Datasets, XML documents, etc.<br />In Visual Studio 2008, Visual C# and Visual Basic are the languages that implement the LINQ language extensions. LINQ language extensions use the new standard query operators API, which is the query language for any collection that implements IEnumerable&lt;T&gt;.</p>
Table of Contents (14 chapters)
LINQ Quickly
Credits
About the Author
About the Reviewer
Preface
Building an ASP.NET Application
LINQ with Outlook

Writing XML as Text Files and CSV Files


As we saw in the previous section, we can convert XML to a different data structure and different data structure to XML. For example, the following code creates an XML tree with Icecreams as the root element:

// Create XML Tree using XElement
XElement ClassicIcecreams =
new XElement("Icecreams",
new XElement("Icecream",
new XElement("Name", "Chocolate Fudge Icecream"),
new XElement("Cholesterol", "50mg"),
new XElement("TotalCarbohydrates", "35g"),
new XElement("Protein",
new XAttribute("VitaminA", "3g"),
new XAttribute("Iron", "1g")),
new XElement("TotalFat",
new XAttribute("SaturatedFat", "9g"),
new XAttribute("TransFat", "11g"))
) );
// Add new type of Icecream to the existing XML
ClassicIcecreams.Add(
new XElement("Icecream",
new XElement("Name", "Vanilla Icecream"),
new XElement("Cholesterol", "65mg"),
new XElement("TotalCarbohydrates", "26g"),
new XElement("Protein", "4g",
new XAttribute("VitaminA", "1g"),
new XAttribute("Calcium", "2g"),
new...