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(TransactionType s trans){...}
//caller
MyClass.SomeMethod(Transac tionTypes. {all enums display})
Is there a way to accomplish this without the problems mentioned above?
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(TransactionType
//caller
MyClass.SomeMethod(Transac
Is there a way to accomplish this without the problems mentioned above?
ASKER
Yes - I'd like to have intellisense.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@PockyMaster:
Can you comment on how you use MyGeneration specifically? I'm just starting to read up on it.
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
SQL Server example:
TransactionType
---------------------
TransactionTypeID, int
TransactionTypeName, varchar(25)