Link to home
Start Free TrialLog in
Avatar of brettr
brettr

asked on

Using database config data in code

[.NET 3.5]
In have several configuration tables in a db and map them via an enum in my .NET app.  The enum may look like this:

public enum TransactionTypes{
start = 1,
end = 2,
complete = 3}

where each number corresponds to an ID column in a corresponding table.   This approach is error prone and not very scalable.  A change in the ID column value can disassociate the enum mapping.  You also have to remember to add any new IDs.   The enum is nice though since I can get great intellisense in code:

//implementation
public static void SomeMethod(TransactionTypes trans){...}

//caller
MyClass.SomeMethod(TransactionTypes.{all enums display})

Is there a way to accomplish this without the problems mentioned above?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Do you want (or need) Intellisense mapping?  The approach that I usually take is to have a TransactionType lookup table that you can access with an SQL inner join.

SQL Server example:

TransactionType
---------------------
TransactionTypeID, int
TransactionTypeName, varchar(25)
Avatar of brettr
brettr

ASKER

Yes - I'd like to have intellisense.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brettr

ASKER

@PockyMaster:
Can you comment on how you use MyGeneration specifically?  I'm just starting to read up on it.
It's merely based on database driven code generation. It has templates included when you download it, but it's easy to write your own using VB script. The help is self explaining, or based on the included templates it's easy to create your own