At the moment I have a SQL Server 2005 table that looks a bit like:
ID | name | desc ---------------------- 1 | ONE | Value One 3 | THREE | Value Three 5 | FIVE | Value Five
This table corresponds with an enum in C# that looks like:
enum MsgTypes{
<summary>Value One</summary>
ONE = 1,
<summary>Value Three</summary>
THREE = 3,
<summary>Value Five</summary>
FIVE = 5
}
So my question is this: Is there a good way to associate the enum to the SQL table so that any changes/additions to the values in the table don’t need to be manually made in the c# code?
If you want it to be somewhat dynamic, why make it an enum to start with? Just fetch the details from the table on app startup, and remember them in (say) a
Dictionary<int, string>. You could always encapsulate the value within your own value type which enforced the range, if you wanted to.Alternatively, if you don’t mind recompiling, you could fetch it at build time and autogenerate the enum source code.