views:

27

answers:

1

I'm trying to make alterations to an existing project, and I've found a project in the solution which is full of generated classes.

Problem is, nobody here can tell me what generated them, so I'm pretty much left with pasting one of the classes in here and hoping someone will be able to tell me where they came from.

The solution I'm working on uses Expression Blend 3 and Visual Studio 2008. Dunno if that's relevant, but I'm trying to give as much information as I can think of... As well as this class, which appears in its own file, there's an "SPResults" file, which contains about 5000 lines of accessor classes of this type. Not quite sure why EndCustomer is in its own file...

From what I can see for myself, there's a stored procedure in one of the databases this program links to, and that SP's name is "GetEndCustomers". Something has then created a class called "EndCustomers" to represent the return type of this procedure.

The first part is a function from a class named Database, which returns a collection of the objects in question.

<FunctionAttribute(Name:="dbo.GetEndCustomers")> _
Public Function GetEndCustomers(<Parameter(Name:="Dummy", DbType:="VarChar(1)")> ByVal Dummy As String) As ISingleResult(Of Data.EndCustomer)
    Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo), Dummy)
    Return CType(result.ReturnValue, ISingleResult(Of Data.EndCustomer))
End Function

This part is the EndCustomer class itself.

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 Data

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

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

        Private _ID As Byte

        Private _Name As String

#Region "Extensibility Method Definitions"
        Partial Private Sub OnLoaded()
        End Sub
        Partial Private Sub OnValidate(ByVal action As System.Data.Linq.ChangeAction)
        End Sub
        Partial Private Sub OnCreated()
        End Sub
        Partial Private Sub OnIDChanging(ByVal value As Integer)
        End Sub
        Partial Private Sub OnIDChanged()
        End Sub
        Partial Private Sub OnNameChanging(ByVal value As String)
        End Sub
        Partial Private Sub OnNameChanged()
        End Sub
#End Region

        Public Sub New()
            MyBase.New()

            OnCreated()
        End Sub

        <Column(Storage:="_ID", AutoSync:=AutoSync.OnInsert, DbType:="TinyInt NOT NULL IDENTITY", IsPrimaryKey:=True, IsDbGenerated:=True)> _
        Public Property ID() As Byte
            Get
                Return Me._ID
            End Get
            Set(ByVal value As Byte)
                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:="_Name", DbType:="VarChar(40) NOT NULL", CanBeNull:=False)> _
        Public Property Name() As String
            Get
                Return Me._Name
            End Get
            Set(ByVal value As String)
                If (String.Equals(Me._Name, value) = False) Then
                    Me.OnNameChanging(value)
                    Me.SendPropertyChanging()
                    Me._Name = value
                    Me.SendPropertyChanged("Name")
                    Me.OnNameChanged()
                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

So, yeah, can anyone tell me what has been used to generate this class? It could be something in Visual Studio, Expression Blend, SQL Server Management Studio, or some obscure bit of software I haven't even noticed is on the PC. Any clues, anyone?

+3  A: 

It looks like Linq2Sql or EntityFramework generated classes.

Check if your project contains a .edmx (EntityFramework) or .dbml (Linq2Sql) file, and you have found the "culprit".

klausbyskov
Windows Search doesn't come up with either of those in the solution directories... I've seen Linq-to-SQL mentioned in searches for the phrase "Extensibility Method Definitions", though. Maybe the original coder deleted the .dbml file...
Frosty840
Yeah, t turns out that the guy has generated all of these classes, then taken apart the generated file, and then taken some, but not all, of the generated classes out to their own .vb files. As an aside, was he right to do things this way (I presume that his changes were to add the iNotifyPropertyChanging implementation to the class), or can the iNotifyPropertyChanged/Changing be added automatically?
Frosty840