Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Imagine you have a database with a table in it.

 

Imagine that you wish to represent this table in your code as a class.

 

What is the most efficient (maintenance-wise) way of representing your database table?

 

Currently, I'm trying to decide. I can either go for something like:

 

Public Class MyClass
   Protected mID as Long
   Protected mSomeField as String
   Protected mSomeOtherField as Long
   .. repeat private member for each database field

#Region "Properties"
Public Property ID() as Long
   Get
       return mID
   End Get
   Set (Byval Value as Long)
      mID = Value
   End Set
End Property 

(... repeat property for each private member)

#End Region

Public Sub New()
   '  perhaps overloaded constructor to handle loading by ID and pre-setting all values
End Sub

Public Sub Save()
    'Various DB code to save back to database
End Sub
End Class

 

 

Or, I could go with a Hashtable-type system, whereby the values are stored in a hashtable, which is the default property of my class. Problem with that is returning the various fields in the correct data-type.

 

I would like this to be as EASY to maintain as possible - if a structural change is made to the database, it would be NICE if the code didn't have to be changed, but this is not a necessity.

 

Somebody out there must have dealt with this problem and come up with a nifty solution?

 

B.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...