O'Reilly logo

Visual Basic 2010 Unleashed by Alessandro Del Sole

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Querying Data with LINQ to SQL

Before you begin querying data with LINQ to SQL, you need to instantiate the DataContext class. Continuing with the console application example started in the previous section, you can declare such an instance at the module level as follows:

Private northwind As New NorthwindDataContext

Class Level Declaration

In this example the instance is declared at the module level because a console application is covered. In most cases you work with client applications such as WPF or Windows Forms; therefore, the instance will be generated at the class level.

Declaring a single instance at the module or class level allows one DataContext to manage entities for all the object model lifetime.

Real-World LINQ

In my client ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required