Each data source provides its own technique for searching and manipulating individual items. What’s common in all data sources is the operations we perform with the data: We want to be able to query the data and select the values we’re interested in. It’s therefore reasonable to assume a common query language for all data… [Continue Reading]
Querying Collections and XML with LINQ
LINQ to Objects
This section focuses on querying collections of objects. As you can guess, the most interesting application of LINQ to Objects is to select items from a collection of custom objects. Let’s create a custom class to represent products: I’m not showing the implementation of various properties, because they’re quite trivial (nothing more than the default… [Continue Reading]
Aggregating with LINQ
LINQ allows you to query for aggregates too. By default, it adds a few extended methods for calculating aggregates to all collections. Let’s return to our array of integers, the data array. To calculate the count of all values, call the Count method of the data array. The count of elements in the data array… [Continue Reading]
LINQ to XML / Traversing XML Documents
In this section, we’ll move on to a more interesting component of LINQ, the LINQ to XML component. XML is gaining in popularity and acceptance, and Microsoft has decided to promote XML to a basic data type. Yes, XML is a data type like integers and strings! To understand how far VB is taking XML,… [Continue Reading]
Adding Dynamic Content to an XML Document
The XML documents we’ve built in our code so far were static. Because XML support is built into VB, you can also create dynamic context, and this is where things get quite interesting. To insert some dynamic content into an XML document, insert the characters <%=. The editor will automatically insert the closing tag, which… [Continue Reading]
LINQ to SQL
SQL stands for Structured Query Language, a language for querying databases. SQL is discussed in detail in Chapter “Basic Concepts of Relational Databases”, and as you will see, SQL resembles LINQ. If you are not familiar with databases and SQL, you should read Chapter “Basic Concepts of Relational Databases” and then return to this section…. [Continue Reading]