Tuesday, December 30, 2008

Linq Projection in Vb

This tutorial was created with Microsoft Visual Stuio.NET 2008. 2005 can be used, but you must install Microsoft's LINQ Community Technology Preview release.

In this tutorial we will look at LINQ Projection, which is when we can select specific data from a source without retrieving all fields. We will be creating a class to define a list in which we will create a number of people with IDs, names and cities. Then we will use buttons to select only parts of this data.

First, we will start off by creating a new Windows Form application in VS.NET 2008. Next, we will create a class - call it aList - and define our list object:


Public Class aList
Private _personID As Integer
Private _name As String
Private _city As String

Public Property PersonID() As Integer
Get
Return _personID
End Get
Set(ByVal value As Integer)
_personID = value
End Set
End Property

Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property

Public Property City() As String
Get
Return _city
End Get
Set(ByVal value As String)
_city = value
End Set
End Property
End Class

This class defines a Property for each field we want, and its data type.
Next, we can add our Controls to the Form. We will add three buttons, and a Rich TextBox. The buttons will retrieve all of the IDs, Names and Cities, individually. This will demonstrates how we can retrieve the specific data that we want. Once we have our controls, we can move onto the code-behind of the form and define our data. We will add a few sample entries:

Please visit Linqhelp.com to complete this article. Happy Coding!

No comments:

Post a Comment