473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

extra database reads in a business object class

This has been bothering me for a long time, and I'm curious about everyone's
opinion or a "Microsoft Best Practices" method of doing this. I have a
"Member" business object which contains information about an individual
member. For instance, it contains the following properties:

member.name = "SteveS"
member.LoginName = "SteveS"
member.Phone = '555-555-1234'
member.Office = ...object of office information such as (office.address1,
office.name, office.mailtype, etc...)
member.Committees = ....contains a collection of the Committee objects
(Committee.Name, Committee.Type, Committee.MeetingPlace, etc...)

So, every time I instantiate the member object, I populate the .Office and
..Committes objects. Basically, in this example, the database would take 3
hits - one to read the member record, one to read the office record, and
one to read the committee records.

THE PROBLEM: This works fine, except there are 2 extra database hits when
I only need the LoginName property. ***I hate to call the database again if
I don't have to****

THE SOLUTION: ???? What do you think is the best answer???? Once answer
is to read all the data in a sql statement, then use that to populate each
object. That doesn't seem to be the cleanest way to me. (but I could be
wrong). Here's what I did:
Public Class Member

private _name as string
private _MemberNumber as Long
private _LoginName as string
private _Phone as string
private_Office as Business.Office
private _Committees as Business.CommitteCollection()

Public Property Name as String
....
End Property
Public Property LoginName as String
....
End Property
Public ReadOnly Property as Business.Office
Get
If IsNothing(_office) then '<======= populate the office object
if not already
_Office = New Office(_OfficeNumber)
End If
End Get
End Property
Public ReadOnly Committees Property as Business as
Business.CommitteeCollection()
Get
If IsNothing(_Committees) Then '<=======populate the
CommitteCollection if not already
...code to populate the CommitteCollection.....
End If
return _Committees
End Get
End Property
.....
.....
End Class
Thanks for taking the time to think about this :-)

SteveS
Jul 21 '05 #1
1 1335
I've used this approach in the past as well - i.e. load collections as they
are requested.

One variation I have also used on this approach is to include some type of
optional "level" parameter in the constructor. So, if I know I plan on
using various collections, I can pass in a level of, say "1", when I
instantiate the object and it will know to go ahead and load some of the
collections (rather than wait until I access them) since I know they will be
accessed.

--
Thanks, Jeff
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SteveS | last post by:
I'm not sure if this is the right forum, but here it goes :-) This has been bothering me for a long time, and I'm curious about everyone's opinion or a "Microsoft Best Practices" method of doing...
1
by: SteveS | last post by:
This has been bothering me for a long time, and I'm curious about everyone's opinion or a "Microsoft Best Practices" method of doing this. I have a "Member" business object which contains...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
1
by: Nemisis | last post by:
hi guys, Currently converting an old classic asp system to a OOP asp.net application. We are building the new application using a 3 tier arcitecture and i was wondering about the following. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.