Instantiating the ObjectContext

The first task you need to accomplish when working with the ADO.NET Entity Framework in code to get an instance of the ObjectContext class. At the beginning of this chapter I told you to create a new Visual Basic project for the Console, so let’s continue on this path. At module level (or class level, in most common scenarios) declare a variable of type NorthwindEntities that represents our object context as follows:

Private northwindContext As NorthwindEntities

Within the Sub Main (or in the constructor if you work with classes), create the actual instance:

image

Notice how a System.Data.SqlClient.SqlException general ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.