views:

308

answers:

2

I am building a module using linq to SQL and I am running into some problems. I have been following Michal Washington's tutorial on adefwebserver.com. The problem is that VB does not recognize my Complaint Class when I try to create new Complaint object. Any idea why I am unable to Dim a Complaint object? Here is my code:

View.ascx.vb(

Imports Complaint
    Protected Sub LinqDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceInsertEventArgs) Handles LinqDataSource1.Inserting

        Dim Complaint As **Complaint** = DirectCast(e.NewObject, Complaint)

        Complaint.UserID = Entities.Users.UserController.GetCurrentUserInfo().Username
        Complaint.ModuleId = ModuleId
        Complaint.System_Time_Date_Stamp = Format(DateTime.Now, "yyyy-MM-dd HH:mm:ss.fff")

    End Sub

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim Complaint As Complaint = (DirectCast((e.Row.DataItem), Complaint))

            If (PortalSecurity.IsInRole("Administrators")) Then
                e.Row.Cells(0).Enabled = True
            Else
                e.Row.Cells(0).Text = " "
            End If
        End If

    End Sub

)

Complaint.designer.vb(

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

Namespace Complaint


<System.Data.Linq.Mapping.DatabaseAttribute(Name:="NewDnn")>  _
Partial Public Class ComplaintDataContext
 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
Partial Private Sub InsertComplaint(instance As Complaint)
End Sub
Partial Private Sub UpdateComplaint(instance As Complaint)
End Sub
Partial Private Sub DeleteComplaint(instance As Complaint)
End Sub
#End Region

 Public Sub New()
  MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("SiteSqlServer").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 Complaints() As System.Data.Linq.Table(Of Complaint)
  Get
   Return Me.GetTable(Of Complaint)
  End Get
 End Property
End Class

<Table(Name:="dbo.Complaint")>  _
Partial Public Class Complaint
 Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged

 Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)

 Private _ID As Integer

 Private _ModuleID As System.Nullable(Of Integer)

 Private _Member_UserName As String

 Private _Reporter_Preffered_Contact As String

 Private _Target_FName As String

 Private _Target_LName As String

 Private _Target_Street_Address As String

 Private _Target_City As String

 Private _Target_State As String

 Private _Target_Zip As String

 Private _Complaint_Details As String

 Private _Status As String

 Private _System_Time_Date_Stamp As System.Nullable(Of Date)

#Region "Extensibility Method Definitions"
Partial Private Sub OnLoaded()
End Sub
Partial Private Sub OnValidate(action As System.Data.Linq.ChangeAction)
End Sub
Partial Private Sub OnCreated()
End Sub
Partial Private Sub OnIDChanging(value As Integer)
End Sub
Partial Private Sub OnIDChanged()
End Sub
Partial Private Sub OnModuleIDChanging(value As System.Nullable(Of Integer))
End Sub
Partial Private Sub OnModuleIDChanged()
End Sub
Partial Private Sub OnMember_UserNameChanging(value As String)
End Sub
Partial Private Sub OnMember_UserNameChanged()
End Sub
Partial Private Sub OnReporter_Preffered_ContactChanging(value As String)
End Sub
Partial Private Sub OnReporter_Preffered_ContactChanged()
End Sub
Partial Private Sub OnTarget_FNameChanging(value As String)
End Sub
Partial Private Sub OnTarget_FNameChanged()
End Sub
Partial Private Sub OnTarget_LNameChanging(value As String)
End Sub
Partial Private Sub OnTarget_LNameChanged()
End Sub
Partial Private Sub OnTarget_Street_AddressChanging(value As String)
End Sub
Partial Private Sub OnTarget_Street_AddressChanged()
End Sub
Partial Private Sub OnTarget_CityChanging(value As String)
End Sub
Partial Private Sub OnTarget_CityChanged()
End Sub
Partial Private Sub OnTarget_StateChanging(value As String)
End Sub
Partial Private Sub OnTarget_StateChanged()
End Sub
Partial Private Sub OnTarget_ZipChanging(value As String)
End Sub
Partial Private Sub OnTarget_ZipChanged()
End Sub
Partial Private Sub OnComplaint_DetailsChanging(value As String)
End Sub
Partial Private Sub OnComplaint_DetailsChanged()
End Sub
Partial Private Sub OnStatusChanging(value As String)
End Sub
Partial Private Sub OnStatusChanged()
End Sub
Partial Private Sub OnSystem_Time_Date_StampChanging(value As System.Nullable(Of Date))
End Sub
Partial Private Sub OnSystem_Time_Date_StampChanged()
End Sub
#End Region

 Public Sub New()
  MyBase.New
  OnCreated
 End Sub

 <Column(Storage:="_ID", AutoSync:=AutoSync.OnInsert, DbType:="Int NOT NULL IDENTITY", IsPrimaryKey:=true, IsDbGenerated:=true)>  _
 Public Property ID() As Integer
  Get
   Return Me._ID
  End Get
  Set
   If ((Me._ID = value)  _
      = false) Then
    Me.OnIDChanging(value)
    Me.SendPropertyChanging
    Me._ID = value
    Me.SendPropertyChanged("ID")
    Me.OnIDChanged
   End If
  End Set
 End Property

 <Column(Storage:="_ModuleID", DbType:="Int")>  _
 Public Property ModuleID() As System.Nullable(Of Integer)
  Get
   Return Me._ModuleID
  End Get
  Set
   If (Me._ModuleID.Equals(value) = false) Then
    Me.OnModuleIDChanging(value)
    Me.SendPropertyChanging
    Me._ModuleID = value
    Me.SendPropertyChanged("ModuleID")
    Me.OnModuleIDChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Member_UserName", DbType:="NVarChar(50)")>  _
 Public Property Member_UserName() As String
  Get
   Return Me._Member_UserName
  End Get
  Set
   If (String.Equals(Me._Member_UserName, value) = false) Then
    Me.OnMember_UserNameChanging(value)
    Me.SendPropertyChanging
    Me._Member_UserName = value
    Me.SendPropertyChanged("Member_UserName")
    Me.OnMember_UserNameChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Reporter_Preffered_Contact", DbType:="NVarChar(50)")>  _
 Public Property Reporter_Preffered_Contact() As String
  Get
   Return Me._Reporter_Preffered_Contact
  End Get
  Set
   If (String.Equals(Me._Reporter_Preffered_Contact, value) = false) Then
    Me.OnReporter_Preffered_ContactChanging(value)
    Me.SendPropertyChanging
    Me._Reporter_Preffered_Contact = value
    Me.SendPropertyChanged("Reporter_Preffered_Contact")
    Me.OnReporter_Preffered_ContactChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Target_FName", DbType:="NVarChar(50)")>  _
 Public Property Target_FName() As String
  Get
   Return Me._Target_FName
  End Get
  Set
   If (String.Equals(Me._Target_FName, value) = false) Then
    Me.OnTarget_FNameChanging(value)
    Me.SendPropertyChanging
    Me._Target_FName = value
    Me.SendPropertyChanged("Target_FName")
    Me.OnTarget_FNameChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Target_LName", DbType:="NVarChar(50)")>  _
 Public Property Target_LName() As String
  Get
   Return Me._Target_LName
  End Get
  Set
   If (String.Equals(Me._Target_LName, value) = false) Then
    Me.OnTarget_LNameChanging(value)
    Me.SendPropertyChanging
    Me._Target_LName = value
    Me.SendPropertyChanged("Target_LName")
    Me.OnTarget_LNameChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Target_Street_Address", DbType:="NVarChar(100)")>  _
 Public Property Target_Street_Address() As String
  Get
   Return Me._Target_Street_Address
  End Get
  Set
   If (String.Equals(Me._Target_Street_Address, value) = false) Then
    Me.OnTarget_Street_AddressChanging(value)
    Me.SendPropertyChanging
    Me._Target_Street_Address = value
    Me.SendPropertyChanged("Target_Street_Address")
    Me.OnTarget_Street_AddressChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Target_City", DbType:="NVarChar(50)")>  _
 Public Property Target_City() As String
  Get
   Return Me._Target_City
  End Get
  Set
   If (String.Equals(Me._Target_City, value) = false) Then
    Me.OnTarget_CityChanging(value)
    Me.SendPropertyChanging
    Me._Target_City = value
    Me.SendPropertyChanged("Target_City")
    Me.OnTarget_CityChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Target_State", DbType:="NVarChar(50)")>  _
 Public Property Target_State() As String
  Get
   Return Me._Target_State
  End Get
  Set
   If (String.Equals(Me._Target_State, value) = false) Then
    Me.OnTarget_StateChanging(value)
    Me.SendPropertyChanging
    Me._Target_State = value
    Me.SendPropertyChanged("Target_State")
    Me.OnTarget_StateChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Target_Zip", DbType:="NVarChar(50)")>  _
 Public Property Target_Zip() As String
  Get
   Return Me._Target_Zip
  End Get
  Set
   If (String.Equals(Me._Target_Zip, value) = false) Then
    Me.OnTarget_ZipChanging(value)
    Me.SendPropertyChanging
    Me._Target_Zip = value
    Me.SendPropertyChanged("Target_Zip")
    Me.OnTarget_ZipChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Complaint_Details", DbType:="NVarChar(4000)")>  _
 Public Property Complaint_Details() As String
  Get
   Return Me._Complaint_Details
  End Get
  Set
   If (String.Equals(Me._Complaint_Details, value) = false) Then
    Me.OnComplaint_DetailsChanging(value)
    Me.SendPropertyChanging
    Me._Complaint_Details = value
    Me.SendPropertyChanged("Complaint_Details")
    Me.OnComplaint_DetailsChanged
   End If
  End Set
 End Property

 <Column(Storage:="_Status", DbType:="NVarChar(4000)")>  _
 Public Property Status() As String
  Get
   Return Me._Status
  End Get
  Set
   If (String.Equals(Me._Status, value) = false) Then
    Me.OnStatusChanging(value)
    Me.SendPropertyChanging
    Me._Status = value
    Me.SendPropertyChanged("Status")
    Me.OnStatusChanged
   End If
  End Set
 End Property

 <Column(Storage:="_System_Time_Date_Stamp", DbType:="DateTime")>  _
 Public Property System_Time_Date_Stamp() As System.Nullable(Of Date)
  Get
   Return Me._System_Time_Date_Stamp
  End Get
  Set
   If (Me._System_Time_Date_Stamp.Equals(value) = false) Then
    Me.OnSystem_Time_Date_StampChanging(value)
    Me.SendPropertyChanging
    Me._System_Time_Date_Stamp = value
    Me.SendPropertyChanged("System_Time_Date_Stamp")
    Me.OnSystem_Time_Date_StampChanged
   End If
  End Set
 End Property

 Public Event PropertyChanging As PropertyChangingEventHandler Implements System.ComponentModel.INotifyPropertyChanging.PropertyChanging

 Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

 Protected Overridable Sub SendPropertyChanging()
  If ((Me.PropertyChangingEvent Is Nothing)  _
     = false) Then
   RaiseEvent PropertyChanging(Me, emptyChangingEventArgs)
  End If
 End Sub

 Protected Overridable Sub SendPropertyChanged(ByVal propertyName As [String])
  If ((Me.PropertyChangedEvent Is Nothing)  _
     = false) Then
   RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
  End If
 End Sub
End Class
End Namespace

)

A: 

Using "Complaint" as the NameSpace, Class name, and Object name is a bad idea and might be causing your problem. I know you can name the variable the same as the class in C# but I'm not sure it's legal in VB.NET, it's not something I do since it can be confusing on whether you're referring to the instance or the class.

EfficionDave
A: 

I ran into an issue similar to this. My app code was in a folder above my DesktopModules folder, so the designer put the incorrect namespace in my designer.vb file.

All of my other .vb files had Namespace Modules.CGaming but the auto generated one only had Namespace CGaming

Once I modified the namespace on my designer.vb file, it was available in the context.

Hope this helps!

Robert