views:

474

answers:

2

I'm just learning to work with partial classes in VB.NET and VS2008. Specifically, I'm trying to extend a LINQ to SQL class that was automatically created by SqlMetal.

The automatically generated class looks like this:

Partial Public Class DataContext
    Inherits System.Data.Linq.DataContext

 ...


<Table(Name:="dbo.Concessions")>  _
Partial Public Class Concession

 ...

     <Column(Storage:="_Country", DbType:="Char(2)")>  _
   Public Property Country() As String
          ...
    End Property

 ...

End Class

In a separate file, here's what I'm trying to do:

Partial Public Class DataContext

    Partial Public Class Concession

        Public Function Foo() as String
            Return DoSomeProcessing(Me.Country)
        End Function

    End Class

End Class

... but I get blue jaggies under 'Me.Country' and the message 'Country' is not a member of 'DataContext.Concession'. Both halves of the partial class are in the same namespace.

So how do I access the properties of the automatically-generated half of the partial class, from my half of the partial class?

+3  A: 

Unless VB.NET generates different stuff in its LINQ to SQL files from C# the classes of the DB tables aren't within the DataContext class, just beside it.

So you have the class MyNamespace.DataContext.Concession when the other half of the partial class is realy MyNamespace.Concession

Slace
That's it! Thanks for the pointer.
Herb Caudill
A: 

That is just spiffy. I did not notice the entities are stand alone not nested. Duh. First, I had to ask the right question of The Google, at whose alter I worship. Thank you.