同步参照完整性表和枚举 [英] Syncing referential integrity tables and enums

查看:184
本文介绍了同步参照完整性表和枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我思考这个问题,从时间到时间,所以我想我会问你关于它的家伙。

I ponder this question from time to time, so I thought I'd ask you guys 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 ensuring referential integrity. It is basically an enum stored in the database for the purposes of ensuring that any Visiblity values that appear in other tables are always valid.

在我的前端,我有。一些选择

Over in my front end, I have some choices.


  1. 我可以查询该表并将其存储在,比如说,一个词典<字符串,整数> 词典< INT,串>

  2. 我可以手工编写一个枚举。 ,只是在手动极少数情况下,有一个变化表编辑值。例如,

  1. I could query this table and store it in, say, a Dictionary<string, int> or a Dictionary<int, string>.
  2. I could write an enum by hand and just manually edit the values in the rare event that there is a change to the table. E.g.,

公开枚举的可见
{
可见,
隐形,
折叠
}

你会建议哪个?为什么?

Which would you advise and why?

感谢。

推荐答案

对于这样相当琐碎的东西,我通常用一个枚举走。我可以跟你确定这个意义上,我觉得这是不完全正确的......但在我看来,这是两害相权较小

For fairly trivial stuff like this, I usually go with an enum. I can identify with you in the sense that I feel it's not completely right... but in my opinion it's the lesser of two evils.

有关这方面的一些额外的理由:如果由于某种原因的第四值分别为要添加,您的代码将需要更新无论如何能够能够处理的。当你在它,这是非常麻烦一点也更新枚举。

Some additional justification for this: if for some reason a fourth value were to be added, your code would need updating anyway to be able to be able to handle that. While you're at it, it's very little trouble to also update the enum.

这篇关于同步参照完整性表和枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆