Well, this will work, but it creates a bit of overhead. Generally what I do is create scalar methods in the Foreign Key tables that will return just the value that I need. Then in the custom property I will call that scalar method. Instead of create privates for all of the BOs, which is actually fine, you can also implement the Using operator. For example, we have a BO that houses all of our Countries and another for States (or provinces). Each place that has a state or country field is just a PK (foreign key field).
So let's just take the country BO. First I create a scalar method in the Country BO that will return just the country name:
Public FUnction GetCountryName(Byval CountryPK As Integer) As System.String
'-- Establish Locals
Dim loCommand As New SqlCommand()
'-- Build the command text
loCommand.CommandText = "SELECT ct_Name FROM Country WHERE ct_pk = @ct_pk"
'-- Create the parms
loCommand.Parameters.Add("@ct_pk", Int)
'-- Set the parms
loCommand.Parameters("@ct_pk").Value = CountryPK
'-- Return the results
Return CType(Me.ExecuteScalar(loCommand), System.String)
End Function
Now that that is written, in the BO that has a foriegn key field, you can create a custom property and add some code that looks like this:
Public Readonly Property MyCountry As System.String
Get
Using Country As new CountryBO
Return Country.GetCountryName(Me.my_country_pk)
End Using
End Get
End Property
Let me know if this doesn;t make any sense.