开发者

VB Partial class... stuck!

I'm stuck when trying to create the simplest partial class in order to access a table property.

I have a LINQ auto generated DataContext with:

Namespace VuBridgeDB
    <System.Data.Linq.Mapping.DatabaseAttribute(Name:="C:\Users\Didier\Documents\Visual Studio 2010\Projects\VuBridge1\VuBridge1\Data\VuBridgeDB.sdf")> _
    Partial Public Class myClassDataContext
        Inherits System.Data.Linq.DataContext

        Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource _ 
                = New System.Data.Linq.Mapping.AttributeMappingSource()

        Partial Private Sub InsertCompetitions(ByVal instance As Competitions)
        End Sub
    End Class

<Table(Name:="Competitions")> _
    Partial Public Class Competitions    

        Partial Private Sub OnC_TitleChanged()
        End Sub
    End Class

Now I try to add my own开发者_运维知识库 business logic in a class of mine:

Public Class myClassDataContext    
    Private Sub InsertCompetitions(ByVal instance As Competitions)
    End Sub
End Class    

Public Class Competitions
    Private Sub onC_SiteChanged()
            Me.
    End Sub
End Class

Problem:

  1. VB.NET refuses the class name myClassDataContext saying it already exists.

  2. I was expecting the C_Site property to be available in my own class (as well as other Competitions columns), but when I type "Me.", IntelliSense doesn't give me any of the Competitions properties (ie data columns).

I've tried all sorts of Partial Public, adding namespace the same as the one used in the auto-generated... Nothing works.

Can someone provide with a working sample please?


You need to make your other declaration of myClassDataContext partial too:

 Public Partial Class myClassDataContext
     Private Sub InsertCompetitions(ByVal instance As Competitions)
         ...
     End Sub
     ...
 End Class

Otherwise the VB compiler thinks you're trying to declare another "standalone" class which happens to have the same name.

This will fix both of your problems - the other properties etc currently aren't present in your "extra" class code for exactly the same reason.


Ok, thanks guys... I finally get that stuff working, by adding the same Namespace declaration, like this:

Namespace VuBridgeDB
Partial Public Class VubridgeDB

    Private Sub InsertCompetitions(ByVal instance As Competitions)

        MsgBox("Inserting " & instance.C_Title, vbInformation)

    End Sub

End Class

End Namespace

Once this is done, Intellisense fully recognizes the instance parameter.


The class declaration that works with us is simply Partial Class myClassDataContext in a separate file, nothing more. This should be in the same assembly (dll or exe) and namespace of the original class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜