?
Solved

Getting "Type is not defined" error when trying to use LINQ to SQL

Posted on 2010-01-10
14
Medium Priority
?
595 Views
Last Modified: 2013-11-26
I'm trying to use LINQ to SQL for the first time in a test application.  This is a 3.5 .NET app that I'm developing in Visual Studio 2008 using VB .NET and SQL Server Express 2008.  I performed the following steps:
1. Created a folder name App_Code.
2. Created a LINQ to SQL class named pnContacts under that folder.
3. Dropped a table from the Server Explorer on the left pane of the Object Relational Designer of the class.
4. In the Page_Load event of a page in the project tried to reference the class which is where the error is occurring.

Below is my Page_Load code and  the auto generated code for the class: You can see the partial class, "pnContactsDataContext" is defined in the auto generated code yet I can use it in the Page_Load event.  Is there some aspect of partial classes or LINQ to SQL that I'm not getting?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Using myDataContext As New pnContactsDataContext
		End Using
	End Sub



Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Linq
Imports System.Data.Linq.Mapping
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Reflection


<System.Data.Linq.Mapping.DatabaseAttribute(Name:="Contacts")>  _
Partial Public Class pnContactsDataContext
	Inherits System.Data.Linq.DataContext
	
	Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource = New AttributeMappingSource
	
  #Region "Extensibility Method Definitions"
  Partial Private Sub OnCreated()
  End Sub
  #End Region
	
	Public Sub New()
		MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("ContactsConnectionString").ConnectionString, mappingSource)
		OnCreated
	End Sub
	
	Public Sub New(ByVal connection As String)
		MyBase.New(connection, mappingSource)
		OnCreated
	End Sub
	
	Public Sub New(ByVal connection As System.Data.IDbConnection)
		MyBase.New(connection, mappingSource)
		OnCreated
	End Sub
	
	Public Sub New(ByVal connection As String, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
		MyBase.New(connection, mappingSource)
		OnCreated
	End Sub
	
	Public Sub New(ByVal connection As System.Data.IDbConnection, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
		MyBase.New(connection, mappingSource)
		OnCreated
	End Sub
	
	Public ReadOnly Property MailingLists() As System.Data.Linq.Table(Of MailingList)
		Get
			Return Me.GetTable(Of MailingList)
		End Get
	End Property
End Class

<Table(Name:="dbo.MailingList")>  _
Partial Public Class MailingList
	
	Private _First_Name As String
	
	Private _Last_Name As String
	
	Private _Title As String
	
	Private _Organization As String
	
	Private _Address1 As String
	
	Private _Address2 As String
	
	Private _City As String
	
	Private _State As String
	
	Private _Zip As String
	
	Private _County As String
	
	Private _Phone As String
	
	Private _WorkPhone As String
	
	Private _CellPhone As String
	
	Private _Fax As String
	
	Private _email As String
	
	Private _Website As String
	
	Private _Membership As String
	
	Private _E_news As Boolean
	
	Private _Ethnicity As String
	
	Private _Primary_Language As String
	
	Private _Birth_Year_of_child_adult As String
	
	Private _School_District As String
	
	Private _Completed_By As String
	
	Private _Date_entered As System.Nullable(Of Date)
	
	Private _Agency As Boolean
	
	Private _Attorneys As Boolean
	
	Private _CCDAMembers As Boolean
	
	Private _CharterSchools As Boolean
	
	Private _Churches As Boolean
	
	Private _Colleges As Boolean
	
	Private _CSE As Boolean
	
	Private _Elected_Official As Boolean
	
	Private _FamilySupportCenters As Boolean
	
	Private _FosterParentAgencies As Boolean
	
	Private _GC As Boolean
	
	Private _Hospitals As Boolean
	
	Private _Immigrants_and_Refugees As Boolean
	
	Private _HolidayCards As Boolean
	
	Private _Judges As Boolean
	
	Private _Leadership_Buffalo As Boolean
	
	Private _Listservs As Boolean
	
	Private _MSCList1 As Boolean
	
	Private _MSCSupervisors As Boolean
	
	Private _NonPubBfloSchools As Boolean
	
	Private _Other As Boolean
	
	Private _Parent As Boolean
	
	Private _Pediatricians As Boolean
	
	Private _PNBoardMembers As Boolean
	
	Private _PrincipalsAndSupers As Boolean
	
	Private _Psychologists As Boolean
	
	Private _Publications As Boolean
	
	Private _Radio As Boolean
	
	Private _RecreationAndLeisure As Boolean
	
	Private _SETRC As Boolean
	
	Private _SocialWorkers As Boolean
	
	Private _SpecEdTchr As Boolean
	
	Private _TeacherCenterList As Boolean
	
	Private _Television As Boolean
	
	Private _TransitionCommittee As Boolean
	
	Private _Vendor As Boolean
	
	Private _Western_NY_PTA As Boolean
	
	Private _WNYParentGroups As Boolean
	
	Private _WNYSIN As Boolean
	
	Private _Enews As Boolean
	
	Private _NewsLetter As Boolean
	
	Private _Member As Boolean
	
	Public Sub New()
		MyBase.New
	End Sub
	
	<Column(Name:="[First Name]", Storage:="_First_Name", DbType:="NVarChar(255)")>  _
	Public Property First_Name() As String
		Get
			Return Me._First_Name
		End Get
		Set
			If (String.Equals(Me._First_Name, value) = false) Then
				Me._First_Name = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Last Name]", Storage:="_Last_Name", DbType:="NVarChar(255)")>  _
	Public Property Last_Name() As String
		Get
			Return Me._Last_Name
		End Get
		Set
			If (String.Equals(Me._Last_Name, value) = false) Then
				Me._Last_Name = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Title", DbType:="NVarChar(50)")>  _
	Public Property Title() As String
		Get
			Return Me._Title
		End Get
		Set
			If (String.Equals(Me._Title, value) = false) Then
				Me._Title = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Organization", DbType:="NVarChar(255)")>  _
	Public Property Organization() As String
		Get
			Return Me._Organization
		End Get
		Set
			If (String.Equals(Me._Organization, value) = false) Then
				Me._Organization = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Address1", DbType:="NVarChar(255)")>  _
	Public Property Address1() As String
		Get
			Return Me._Address1
		End Get
		Set
			If (String.Equals(Me._Address1, value) = false) Then
				Me._Address1 = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Address2", DbType:="NVarChar(50)")>  _
	Public Property Address2() As String
		Get
			Return Me._Address2
		End Get
		Set
			If (String.Equals(Me._Address2, value) = false) Then
				Me._Address2 = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_City", DbType:="NVarChar(255)")>  _
	Public Property City() As String
		Get
			Return Me._City
		End Get
		Set
			If (String.Equals(Me._City, value) = false) Then
				Me._City = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_State", DbType:="NVarChar(255)")>  _
	Public Property State() As String
		Get
			Return Me._State
		End Get
		Set
			If (String.Equals(Me._State, value) = false) Then
				Me._State = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Zip", DbType:="NVarChar(255)")>  _
	Public Property Zip() As String
		Get
			Return Me._Zip
		End Get
		Set
			If (String.Equals(Me._Zip, value) = false) Then
				Me._Zip = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_County", DbType:="NVarChar(255)")>  _
	Public Property County() As String
		Get
			Return Me._County
		End Get
		Set
			If (String.Equals(Me._County, value) = false) Then
				Me._County = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Phone", DbType:="NVarChar(255)")>  _
	Public Property Phone() As String
		Get
			Return Me._Phone
		End Get
		Set
			If (String.Equals(Me._Phone, value) = false) Then
				Me._Phone = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_WorkPhone", DbType:="NVarChar(50)")>  _
	Public Property WorkPhone() As String
		Get
			Return Me._WorkPhone
		End Get
		Set
			If (String.Equals(Me._WorkPhone, value) = false) Then
				Me._WorkPhone = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_CellPhone", DbType:="NVarChar(50)")>  _
	Public Property CellPhone() As String
		Get
			Return Me._CellPhone
		End Get
		Set
			If (String.Equals(Me._CellPhone, value) = false) Then
				Me._CellPhone = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Fax", DbType:="NVarChar(255)")>  _
	Public Property Fax() As String
		Get
			Return Me._Fax
		End Get
		Set
			If (String.Equals(Me._Fax, value) = false) Then
				Me._Fax = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_email", DbType:="NVarChar(255)")>  _
	Public Property email() As String
		Get
			Return Me._email
		End Get
		Set
			If (String.Equals(Me._email, value) = false) Then
				Me._email = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Website", DbType:="NVarChar(255)")>  _
	Public Property Website() As String
		Get
			Return Me._Website
		End Get
		Set
			If (String.Equals(Me._Website, value) = false) Then
				Me._Website = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Membership", DbType:="NVarChar(4)")>  _
	Public Property Membership() As String
		Get
			Return Me._Membership
		End Get
		Set
			If (String.Equals(Me._Membership, value) = false) Then
				Me._Membership = value
			End If
		End Set
	End Property
	
	<Column(Name:="[E-news]", Storage:="_E_news", DbType:="Bit NOT NULL")>  _
	Public Property E_news() As Boolean
		Get
			Return Me._E_news
		End Get
		Set
			If ((Me._E_news = value)  _
						= false) Then
				Me._E_news = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Ethnicity", DbType:="NVarChar(50)")>  _
	Public Property Ethnicity() As String
		Get
			Return Me._Ethnicity
		End Get
		Set
			If (String.Equals(Me._Ethnicity, value) = false) Then
				Me._Ethnicity = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Primary Language]", Storage:="_Primary_Language", DbType:="NVarChar(50)")>  _
	Public Property Primary_Language() As String
		Get
			Return Me._Primary_Language
		End Get
		Set
			If (String.Equals(Me._Primary_Language, value) = false) Then
				Me._Primary_Language = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Birth Year of child/adult]", Storage:="_Birth_Year_of_child_adult", DbType:="NVarChar(4)")>  _
	Public Property Birth_Year_of_child_adult() As String
		Get
			Return Me._Birth_Year_of_child_adult
		End Get
		Set
			If (String.Equals(Me._Birth_Year_of_child_adult, value) = false) Then
				Me._Birth_Year_of_child_adult = value
			End If
		End Set
	End Property
	
	<Column(Name:="[School District]", Storage:="_School_District", DbType:="NVarChar(50)")>  _
	Public Property School_District() As String
		Get
			Return Me._School_District
		End Get
		Set
			If (String.Equals(Me._School_District, value) = false) Then
				Me._School_District = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Completed By]", Storage:="_Completed_By", DbType:="NVarChar(3)")>  _
	Public Property Completed_By() As String
		Get
			Return Me._Completed_By
		End Get
		Set
			If (String.Equals(Me._Completed_By, value) = false) Then
				Me._Completed_By = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Date entered]", Storage:="_Date_entered", DbType:="DateTime")>  _
	Public Property Date_entered() As System.Nullable(Of Date)
		Get
			Return Me._Date_entered
		End Get
		Set
			If (Me._Date_entered.Equals(value) = false) Then
				Me._Date_entered = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Agency", DbType:="Bit NOT NULL")>  _
	Public Property Agency() As Boolean
		Get
			Return Me._Agency
		End Get
		Set
			If ((Me._Agency = value)  _
						= false) Then
				Me._Agency = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Attorneys", DbType:="Bit NOT NULL")>  _
	Public Property Attorneys() As Boolean
		Get
			Return Me._Attorneys
		End Get
		Set
			If ((Me._Attorneys = value)  _
						= false) Then
				Me._Attorneys = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_CCDAMembers", DbType:="Bit NOT NULL")>  _
	Public Property CCDAMembers() As Boolean
		Get
			Return Me._CCDAMembers
		End Get
		Set
			If ((Me._CCDAMembers = value)  _
						= false) Then
				Me._CCDAMembers = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_CharterSchools", DbType:="Bit NOT NULL")>  _
	Public Property CharterSchools() As Boolean
		Get
			Return Me._CharterSchools
		End Get
		Set
			If ((Me._CharterSchools = value)  _
						= false) Then
				Me._CharterSchools = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Churches", DbType:="Bit NOT NULL")>  _
	Public Property Churches() As Boolean
		Get
			Return Me._Churches
		End Get
		Set
			If ((Me._Churches = value)  _
						= false) Then
				Me._Churches = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Colleges", DbType:="Bit NOT NULL")>  _
	Public Property Colleges() As Boolean
		Get
			Return Me._Colleges
		End Get
		Set
			If ((Me._Colleges = value)  _
						= false) Then
				Me._Colleges = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_CSE", DbType:="Bit NOT NULL")>  _
	Public Property CSE() As Boolean
		Get
			Return Me._CSE
		End Get
		Set
			If ((Me._CSE = value)  _
						= false) Then
				Me._CSE = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Elected Official]", Storage:="_Elected_Official", DbType:="Bit NOT NULL")>  _
	Public Property Elected_Official() As Boolean
		Get
			Return Me._Elected_Official
		End Get
		Set
			If ((Me._Elected_Official = value)  _
						= false) Then
				Me._Elected_Official = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_FamilySupportCenters", DbType:="Bit NOT NULL")>  _
	Public Property FamilySupportCenters() As Boolean
		Get
			Return Me._FamilySupportCenters
		End Get
		Set
			If ((Me._FamilySupportCenters = value)  _
						= false) Then
				Me._FamilySupportCenters = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_FosterParentAgencies", DbType:="Bit NOT NULL")>  _
	Public Property FosterParentAgencies() As Boolean
		Get
			Return Me._FosterParentAgencies
		End Get
		Set
			If ((Me._FosterParentAgencies = value)  _
						= false) Then
				Me._FosterParentAgencies = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_GC", DbType:="Bit NOT NULL")>  _
	Public Property GC() As Boolean
		Get
			Return Me._GC
		End Get
		Set
			If ((Me._GC = value)  _
						= false) Then
				Me._GC = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Hospitals", DbType:="Bit NOT NULL")>  _
	Public Property Hospitals() As Boolean
		Get
			Return Me._Hospitals
		End Get
		Set
			If ((Me._Hospitals = value)  _
						= false) Then
				Me._Hospitals = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Immigrants and Refugees]", Storage:="_Immigrants_and_Refugees", DbType:="Bit NOT NULL")>  _
	Public Property Immigrants_and_Refugees() As Boolean
		Get
			Return Me._Immigrants_and_Refugees
		End Get
		Set
			If ((Me._Immigrants_and_Refugees = value)  _
						= false) Then
				Me._Immigrants_and_Refugees = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_HolidayCards", DbType:="Bit NOT NULL")>  _
	Public Property HolidayCards() As Boolean
		Get
			Return Me._HolidayCards
		End Get
		Set
			If ((Me._HolidayCards = value)  _
						= false) Then
				Me._HolidayCards = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Judges", DbType:="Bit NOT NULL")>  _
	Public Property Judges() As Boolean
		Get
			Return Me._Judges
		End Get
		Set
			If ((Me._Judges = value)  _
						= false) Then
				Me._Judges = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Leadership Buffalo]", Storage:="_Leadership_Buffalo", DbType:="Bit NOT NULL")>  _
	Public Property Leadership_Buffalo() As Boolean
		Get
			Return Me._Leadership_Buffalo
		End Get
		Set
			If ((Me._Leadership_Buffalo = value)  _
						= false) Then
				Me._Leadership_Buffalo = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Listservs", DbType:="Bit NOT NULL")>  _
	Public Property Listservs() As Boolean
		Get
			Return Me._Listservs
		End Get
		Set
			If ((Me._Listservs = value)  _
						= false) Then
				Me._Listservs = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_MSCList1", DbType:="Bit NOT NULL")>  _
	Public Property MSCList1() As Boolean
		Get
			Return Me._MSCList1
		End Get
		Set
			If ((Me._MSCList1 = value)  _
						= false) Then
				Me._MSCList1 = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_MSCSupervisors", DbType:="Bit NOT NULL")>  _
	Public Property MSCSupervisors() As Boolean
		Get
			Return Me._MSCSupervisors
		End Get
		Set
			If ((Me._MSCSupervisors = value)  _
						= false) Then
				Me._MSCSupervisors = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_NonPubBfloSchools", DbType:="Bit NOT NULL")>  _
	Public Property NonPubBfloSchools() As Boolean
		Get
			Return Me._NonPubBfloSchools
		End Get
		Set
			If ((Me._NonPubBfloSchools = value)  _
						= false) Then
				Me._NonPubBfloSchools = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Other", DbType:="Bit NOT NULL")>  _
	Public Property Other() As Boolean
		Get
			Return Me._Other
		End Get
		Set
			If ((Me._Other = value)  _
						= false) Then
				Me._Other = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Parent", DbType:="Bit NOT NULL")>  _
	Public Property Parent() As Boolean
		Get
			Return Me._Parent
		End Get
		Set
			If ((Me._Parent = value)  _
						= false) Then
				Me._Parent = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Pediatricians", DbType:="Bit NOT NULL")>  _
	Public Property Pediatricians() As Boolean
		Get
			Return Me._Pediatricians
		End Get
		Set
			If ((Me._Pediatricians = value)  _
						= false) Then
				Me._Pediatricians = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_PNBoardMembers", DbType:="Bit NOT NULL")>  _
	Public Property PNBoardMembers() As Boolean
		Get
			Return Me._PNBoardMembers
		End Get
		Set
			If ((Me._PNBoardMembers = value)  _
						= false) Then
				Me._PNBoardMembers = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_PrincipalsAndSupers", DbType:="Bit NOT NULL")>  _
	Public Property PrincipalsAndSupers() As Boolean
		Get
			Return Me._PrincipalsAndSupers
		End Get
		Set
			If ((Me._PrincipalsAndSupers = value)  _
						= false) Then
				Me._PrincipalsAndSupers = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Psychologists", DbType:="Bit NOT NULL")>  _
	Public Property Psychologists() As Boolean
		Get
			Return Me._Psychologists
		End Get
		Set
			If ((Me._Psychologists = value)  _
						= false) Then
				Me._Psychologists = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Publications", DbType:="Bit NOT NULL")>  _
	Public Property Publications() As Boolean
		Get
			Return Me._Publications
		End Get
		Set
			If ((Me._Publications = value)  _
						= false) Then
				Me._Publications = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Radio", DbType:="Bit NOT NULL")>  _
	Public Property Radio() As Boolean
		Get
			Return Me._Radio
		End Get
		Set
			If ((Me._Radio = value)  _
						= false) Then
				Me._Radio = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_RecreationAndLeisure", DbType:="Bit NOT NULL")>  _
	Public Property RecreationAndLeisure() As Boolean
		Get
			Return Me._RecreationAndLeisure
		End Get
		Set
			If ((Me._RecreationAndLeisure = value)  _
						= false) Then
				Me._RecreationAndLeisure = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_SETRC", DbType:="Bit NOT NULL")>  _
	Public Property SETRC() As Boolean
		Get
			Return Me._SETRC
		End Get
		Set
			If ((Me._SETRC = value)  _
						= false) Then
				Me._SETRC = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_SocialWorkers", DbType:="Bit NOT NULL")>  _
	Public Property SocialWorkers() As Boolean
		Get
			Return Me._SocialWorkers
		End Get
		Set
			If ((Me._SocialWorkers = value)  _
						= false) Then
				Me._SocialWorkers = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_SpecEdTchr", DbType:="Bit NOT NULL")>  _
	Public Property SpecEdTchr() As Boolean
		Get
			Return Me._SpecEdTchr
		End Get
		Set
			If ((Me._SpecEdTchr = value)  _
						= false) Then
				Me._SpecEdTchr = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_TeacherCenterList", DbType:="Bit NOT NULL")>  _
	Public Property TeacherCenterList() As Boolean
		Get
			Return Me._TeacherCenterList
		End Get
		Set
			If ((Me._TeacherCenterList = value)  _
						= false) Then
				Me._TeacherCenterList = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Television", DbType:="Bit NOT NULL")>  _
	Public Property Television() As Boolean
		Get
			Return Me._Television
		End Get
		Set
			If ((Me._Television = value)  _
						= false) Then
				Me._Television = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_TransitionCommittee", DbType:="Bit NOT NULL")>  _
	Public Property TransitionCommittee() As Boolean
		Get
			Return Me._TransitionCommittee
		End Get
		Set
			If ((Me._TransitionCommittee = value)  _
						= false) Then
				Me._TransitionCommittee = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Vendor", DbType:="Bit NOT NULL")>  _
	Public Property Vendor() As Boolean
		Get
			Return Me._Vendor
		End Get
		Set
			If ((Me._Vendor = value)  _
						= false) Then
				Me._Vendor = value
			End If
		End Set
	End Property
	
	<Column(Name:="[Western NY PTA]", Storage:="_Western_NY_PTA", DbType:="Bit NOT NULL")>  _
	Public Property Western_NY_PTA() As Boolean
		Get
			Return Me._Western_NY_PTA
		End Get
		Set
			If ((Me._Western_NY_PTA = value)  _
						= false) Then
				Me._Western_NY_PTA = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_WNYParentGroups", DbType:="Bit NOT NULL")>  _
	Public Property WNYParentGroups() As Boolean
		Get
			Return Me._WNYParentGroups
		End Get
		Set
			If ((Me._WNYParentGroups = value)  _
						= false) Then
				Me._WNYParentGroups = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_WNYSIN", DbType:="Bit NOT NULL")>  _
	Public Property WNYSIN() As Boolean
		Get
			Return Me._WNYSIN
		End Get
		Set
			If ((Me._WNYSIN = value)  _
						= false) Then
				Me._WNYSIN = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Enews", DbType:="Bit NOT NULL")>  _
	Public Property Enews() As Boolean
		Get
			Return Me._Enews
		End Get
		Set
			If ((Me._Enews = value)  _
						= false) Then
				Me._Enews = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_NewsLetter", DbType:="Bit NOT NULL")>  _
	Public Property NewsLetter() As Boolean
		Get
			Return Me._NewsLetter
		End Get
		Set
			If ((Me._NewsLetter = value)  _
						= false) Then
				Me._NewsLetter = value
			End If
		End Set
	End Property
	
	<Column(Storage:="_Member", DbType:="Bit NOT NULL")>  _
	Public Property Member() As Boolean
		Get
			Return Me._Member
		End Get
		Set
			If ((Me._Member = value)  _
						= false) Then
				Me._Member = value
			End If
		End Set
	End Property
End Class

Open in new window

0
Comment
Question by:leskelly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26279758
What is the error message?
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 26279888
Hi leskelly;

Your step 2 above is not needed because the Object Relational Designer creates the classes need to map the program data model to the database. You also don't need to wrap the creation of the data context in a Using statement because the data context works in the disconnected state, meaning it opens and closes the connection to the database as needed and the data context gets garbage collection when it goes out of scope.

Other then that what is your question.

Fernando
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		Dim myDataContext As New pnContactsDataContext
		
		' Create your query to thhe database anuse it.
		
End Sub

Open in new window

0
 

Author Comment

by:leskelly
ID: 26279954
In the Page_Load event pnContactsDataContext has a blue line under it.  When I point at it it says "Type pnContactsDataContext is not defined"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 26280404
Hi leskelly;

If pnContactsDataContext is the name of the generated code from the O/R designer then make sure that the namespace name is the same in both the web form and the data context class.

Fernando
0
 

Author Comment

by:leskelly
ID: 26288534
The generated code and the form code you've already seen.  I'm not sure what you mean by the "data context class".
0
 

Author Comment

by:leskelly
ID: 26289746
Hello Fernando,

I was on the run when I made my last post.  What I meant was, isn't the data context class part of the generated code  as given in my code sample:
Partial Public Class pnContactsDataContext
      Inherits System.Data.Linq.DataContext
      
      Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource = New AttributeMappingSource

which matches that given in the code in the web form also given in code sample:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Using myDataContext As New pnContactsDataContext
            End Using
      End Sub

Is there some where else that pnContactsDataContext also needs to be?

Thanks,
Les
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 26290145
Is it possible to post the project or to create a sample project that behaves the same way so that I may look at it?
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 26290149
When I say post I mean upload the complete project current or sample.
0
 

Author Comment

by:leskelly
ID: 26299538
I've attached a self extracting exe of the project
pnContacts.exe
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 26300078
Hi leskelly;

When you add a Linq to SQL class to a project the files are placed in the main project folder. I noticed that you moved yours to a folder called App_Code. If you where to do the following to move it back to the place where the compiler looks for it, it will be available for use in the application.

1. In Solution Explorer right click on the project name.
2. Select the Add on the context menu and then Existing Item...
3. In the window that opens navigate to the App_Code directory and select the file pnContacts.dbml
4. Then click on the Add button at the bottom of the window.
5. The files will be copied to the main project folder.

At this point the line of code in the Page_Load will be valid.

You now can delete the other copy of the dbml file from App_Code.

Fernando
0
 

Author Comment

by:leskelly
ID: 26319892
Hello Fernando,

Thanks for the response however I didn't move the SQL class files to the App_Code folder that is where I created them.  I did it this way as that is what is recommended to two WROX books I have, "Beginning ASP.NET 3.5" AND "Professional ASP.NET 3.5.  According to those books that folder is recognized and treated specially by Visual Studio 2008.  It does give it a different icon than other folders.  Doing what you suggested above did resolve the error however I'd like to get the project to work as the book describes.  Another app that was a sample in the book worked correctly with the SQL class files in that folder.  I've attached the files for the project if you care to look at them.  You can see the file PlanetWrox.dbml which contains the partial class PlanetWroxDataContext is in the App_Code folder and is accessed in the Reviews/All.aspx.vb fille without problem.  Thanks for all you assistance.  I'd appreciate any further insight you have.

Les
BegASPNET.exe
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 26323578
Hi leskelly;

First let me say that I am not a Web developer so some of this stuff is not on the tip of my tongue.

In trying to find out why this was not working as the last project you post I attempted to build a small Web Application to basically do the same thing with no luck, same problem. Then I said to myself, well I used a Web Application templet will I get the same results if I use a Web Site templet? I tried a Web Site templet using from the main IDE menu, File -> New -> Web Site... I then added a ASP.Net folder App_Code and added a dbml model to it. I then went to the main project folder and open the Default.aspx page and added to the Page_Load event a new DataContext that I created in the App_Code folder with no problem. I suspect that this is the same problem you are having. Try creating a new web site and then adding the dbml to the App_Code folder and see that it does work.

Fernando
0
 

Author Comment

by:leskelly
ID: 26377455
Hello Fernando,

I'm sorry it took me so long to reply by other issues demanded my attention.  Anyway you are correct and a little research lead to the quote from MSDN, "Note   The App_Code folder exists for Web site projects in Visual Studio 2005. This folder is not typically included in Web Application Projects."  The same apparently is true of Visual Studio 2008.  Thank you for all of your assistance.

Les
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 26377630
Not a problem, glad I was of some assistance.  ;=)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question