Q: Initialising and updating a class with only static members & database dependency

M

mark4asp

Q: Initialising and updating a class with only static members &
database dependency

I have a class with the following members:

public static List<ACIS> ACIS_List;

static AssetClass() { // blah }

public static ACIS Get_ACIS(string sACISCode) { // blah }

public static ACIS Get_ACIS(int iACIS_Id) { // blah }

Furthermore there are another 6 classes like this - each one has a
static List<T> with methods used to search the List<T> to return data.

Classes fall into 2 different types: (a) those with more or less
fixed, unchanging, data and (b) those having data which may change
daily.

Q1. What is the best way to initialise all these classes at once? I
would like to load all these classes with data at once because that
would only need one hit to the database.

Q2. Taking the reply to Q1 above into account, what is the best kind
of constructor to use? static, private, etc.? Should I be using the
constructor to load the class List<T> with data?

Q3. If some of these Lists become out-of-date, can I set up a
dependency which works to update the List<T> with the most recent data
- i.e. something which works like a cache dependency?
 
G

Guest

Probably the best way to initialize your classes all at once is to call a
method from your global.asax Application_Start handler that gets the data
from the database, and (however your operation works) makes some sort of
action on each static class that causes it to do whatever it does (for
example, excercize a static ctor).

Regarding having a dependency, you could certainly use a SQLCacheDependency
to call your method that you put into the Application_Start handler to
refresh your classes.

Not entirely sure whether having static classes is the answer here, though.
it might be better just to cache the stuff as instances and use the
SqlCacheDependency to invalidate the cached data.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com
 
M

mark4asp

Probably the best way to initialize your classes all at once is to call a
method from your global.asax Application_Start handler that gets the data
from the database, and (however your operation works) makes some sort of
action on each static class that causes it to do whatever it does (for
example, excercize a static ctor).

Regarding having a dependency, you could certainly use a SQLCacheDependency
to call your method that you put into the Application_Start handler to
refresh your classes.

Not entirely sure whether having static classes is the answer here, though.
it might be better just to cache the stuff as instances and use the
SqlCacheDependency to invalidate the cached data.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com















- Show quoted text -

Thanks for the reply Peter. It may be easier to use the Cache but, it
seems to me, not the most efficient way to get things done. When I
want to access say a List<Manager> I must get the object from the
cache, cast it to List<Manager>, check to see whether it's null (then
possibly reload it from the database) before it's ready for use. This
is my dilema. Ease of using the cache against a slight overhead. I
shall try both solutions, but probably go with the one we know works
right now.

PS: I would be very nice if microsoft were to expand the database
dependencies so that objects not in the cache (such as my List<T>s)
could also be set to null when a database table is changed. (Microsoft
- Is anyone listening to me?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top