C # Enum using values ​​in Sql server table

I currently have a SQL Server 2005 table that looks something like this:

ID | name | desc
----------------------
1 | ONE | Value one
3 | THREE | Value Three
5 | FIVE | Value five

This table corresponds to an enumeration in C # that looks like this:

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 way to link the enumeration to the SQL table so that any changes / additions to the values ​​in the table do not need to be manually created in C # code?

+3
source share
5 answers

, , ? () a Dictionary<int, string>. , , .

, , .

+11

- ( ) - <A, B > enum. , , .

, , - , - , , , .

+3

, enums/DB. enum/lookups, , emum + DB row becuase:

  • - , ,
  • - , .
+1

ID, Name Desc, .

0

I agree with what Jon offers, but if you prefer to have your Enum list in the database and want to use them in your code, you can use nHydrate 's TypeTable for your project.

0
source

Source: https://habr.com/ru/post/1777986/


All Articles