开发者

How should i handle public properties?

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

Public Class Custome开发者_开发百科r
    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?


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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜