Synchronization of referential integrity tables and enumerations

I ponder this question from time to time, so I thought I would ask you about it.

Let's say I have a database table that looks like this:

Table: Visibility
Id   Value
--   -----
 0   Visible
 1   Invisible
 2   Collapsed

This is just a table for referential integrity. This is basically an enumeration stored in a database, in order to ensure that any Visiblity values ​​that appear in other tables are always valid.

In my front end, I have a choice.

  • I could query this table and save it, for example, Dictionary<string, int>or Dictionary<int, string>.
  • I could write the enumeration manually and simply manually change the values ​​in the rare case when there is a change in the table. For example.

    public enum Visiblity { Visible, Invisible, Collapsed }

  • Something else????

What would you advise and why?

Thanks.

+4
6

, , . , , ... , , .

: - , , . , .

+2

, ? , enum.

+1

. , , .

+1

, . , .

- -, , , - , , -, enum .

+1

-, , . (, ), int Identity, ID/Value , .

0

Unlike Scott Ivy's answer, I prefer (but rarely use) an approach in which I support only enums, and when starting the application (or, possibly, in the build event) use Reflection to make sure the table values ​​match my enum values, This does not require code generation, but is susceptible to late detection of reference restriction violations.

0
source

All Articles