使用Linq to SQL构建DNN模块时出现问题

时间:2009-10-26 01:04:57

标签: vb.net dotnetnuke

我正在使用linq to SQL构建一个模块,我遇到了一些问题。我一直关注michal Washington在adefwebserver.com上的教程。问题是当我尝试创建新的Complaint对象时,VB无法识别我的投诉类。知道为什么我无法Dim一个投诉对象吗?这是我的代码:

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

2 个答案:

答案 0 :(得分:0)

使用“投诉”作为NameSpace,类名和对象名称是一个坏主意,可能会导致您的问题。我知道你可以将变量命名为与C#中的类相同,但我不确定它在VB.NET中是否合法,这不是我所做的事情,因为无论你是指代实例还是类,它都会让人感到困惑。

答案 1 :(得分:0)

我遇到了类似的问题。我的应用程序代码位于DesktopModules文件夹上方的文件夹中,因此设计人员将不正确的命名空间放在我的designer.vb文件中。

我所有的其他.vb文件都有 命名空间Modules.CGaming 但是自动生成的只有一个 命名空间CGaming

一旦我修改了designer.vb文件中的命名空间,就可以在上下文中使用它。

希望这有帮助!