Reputation: 3519
I am reading Murach's C# 2010 and on the page 522-523 the author introduces a database called MMABooks. The database consists of several tables. One of them seems to be interesting to me because the "interesting" table contains just a single row.
The columns of this "interesting" table are constants: SalesTaxRate
, FirstBookShipCharge
and AdditionalBookShipCharge
.
I am new to programming. I have learnt that constants can be saved in an application config file. My question is
How to decide whether or not I should save the constants in an external config file or save them as a single row in a single table which contains just a single row?
Upvotes: 0
Views: 115
Reputation: 5723
I suppose that in the sample you saw the author wanted to use those values inside of the db too. For instance he could use them inside a joined view or for generating user defined db-function to calculate things. In this case he needs those values in the db.
If you seperate your logic from the db (which I heavily advice you to do!) then you should avoid this pattern strictly and make use of constants and configurations (natural values like miles to kilometers and others should be constants, values changing over time should be configs).
Constructs like code first will take the decision away from you :-).
Upvotes: 1
Reputation: 25526
It might conceivably make sense to put constants in an application config file. The examples you have given though (tax rates and charges) are not constants. They may need to be modified at runtime. A single row table seems like the sensible choice to me.
Upvotes: 0