473,786 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.LoginNam e = "SteveS"
member.Phone = '555-555-1234'
member.Office = ...object of office information such as (office.address 1,
office.name, office.mailtype , etc...)
member.Committe es = ....contains a collection of the Committee objects
(Committee.Name , Committee.Type, Committee.Meeti ngPlace, 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.Commit teCollection()

Public Property Name as String
....
End Property
Public Property LoginName as String
....
End Property
Public ReadOnly Property as Business.Office
Get
If IsNothing(_offi ce) then '<======= populate the office object
if not already
_Office = New Office(_OfficeN umber)
End If
End Get
End Property
Public ReadOnly Committees Property as Business as
Business.Commit teeCollection()
Get
If IsNothing(_Comm ittees) Then '<=======popula te the
CommitteCollect ion if not already
...code to populate the CommitteCollect ion.....
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 1360
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
910
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 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'
1
252
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 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,...
3
2945
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 groups for years, I figure it's time for me to contribute a little bit back, maybe some people out there will find this useful. * Introduction This is a "how-to" style article, showing by example how to dynamically
1
1885
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. I have a parent class, that when inserted, inserts a few child classes into the database, based on other classes. In the old system, this is wrote as one big SQL script, with many inserts and updates because the system was not wrote as OOP.
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.