473,396 Members | 2,037 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,396 software developers and data experts.

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

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

I have a class with the following members:

public static List<ACISACIS_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<Twith methods used to search the List<Tto 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<Twith data?

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

Jul 5 '07 #1
2 1550
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

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

I have a class with the following members:

public static List<ACISACIS_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<Twith methods used to search the List<Tto 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<Twith data?

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

Jul 5 '07 #2
On 5 Jul, 15:54, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
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

"mark4asp" wrote:
Q: Initialising and updating a class with only static members &
database dependency
I have a class with the following members:
public static List<ACISACIS_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<Twith methods used to search the List<Tto 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<Twith data?
Q3. If some of these Lists become out-of-date, can I set up a
dependency which works to update the List<Twith the most recent data
- i.e. something which works like a cache dependency?- Hide quoted text -

- 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<ManagerI 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?)

Jul 5 '07 #3

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

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
9
by: Neil Kiser | last post by:
I'm trying to understand what defining a class as 'static' does for me. Here's an example, because maybe I am thinking about this all wrong: My app will allows the user to control the fonts...
1
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
12
by: mast2as | last post by:
Hi everyone... I have a TExceptionHandler class that is uses in the code to thow exceptions. Whenever an exception is thrown the TExceptionHander constructor takes an error code (int) as an...
8
by: crjjrc | last post by:
Hi, I've got a base class and some derived classes that look something like this: class Base { public: int getType() { return type; } private: static const int type = 0; };
4
by: craigclister | last post by:
I'm writing a small 'learning' app. It uses SQL Server. I am trying to create a common class of database functions. So, am I right in saying that it should be a static class? I've done that, but...
5
by: Ian Collins | last post by:
Consider the following snippet: struct X { static bool called; }; struct Y : X { Y() { called = true; } // g++ is happy with this }; template <int N>
6
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.