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 […]Read More...
Querying Collections and XML with LINQ
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:
Public Class Product
Private _productID As String
Private _productName As String
Private _productPrice As Decimal
Private _productExpDate As Date
Public Property ProductID() As String
Public Property ProductName() As String
Public Property ProductPrice() As Decimal
Public Property ProductExpDate() As Date
I’m not showing the implementation of various properties, because they’re quite trivial (nothing more than the […]Read More...
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 […]Read More...
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, […]Read More...
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 […]Read More...
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. […]Read More...