OrElse
OrElse

Reputation: 9989

How should i handle public properties?

Within my application i have a PUBLIC customer class...

Public Class Customer
    Public Name As String
    Public Surname As String
End Class

Then i decided to use LINQ to SQL within my application. After adding the MyDatabase.dbml class, errors showed up since LINQ creates public properties too

<Column(Storage:="_Name", DbType:="NVarChar(50) NOT NULL", CanBeNull:=false)>  _
    Public Property Name() As String
        Get
            Return Me._Name
        End Get

Here are some errors..

'Name' is already declared as 'Public Name As String' in this class.

'SurName' is already declared as 'Public SurName As String' in this class.

Ok. Thats logical.

But what is the best-practice i should use in the future? I would not like to use the Name and Pluralization options mentioned in ScottGu's blog or rename the properties of my Customer class.

Is there any trick that i am missing?

Upvotes: 0

Views: 172

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503439

Your original code didn't have properties. It had public fields. They a bad idea, basically.

You should just remove the original fields, and use the ones that LINQ to SQL has generated for you. Why would you want two fields (_Name and Name) storing the customer's name, for example?

Upvotes: 1

Related Questions