通过枚举或关系表定义数据状态
我有一个应用程序,在关系数据库中有数据行,该表需要一个状态,该状态始终为
“未提交”、“等待批准”、“已批准”、“已拒绝”
,因为这些永远不会改变,我试图决定实现它们的最佳方法可以考虑一个 Status 枚举,其中包含值和分配的 int,其中 int 被放置到表行的状态列中。
或者链接到该表的状态表,用户选择其中之一作为当前状态。
我无法决定哪个是更好的选项,因为我目前有一个枚举,其中包含审批页面的这些值来填充下拉列表等并设置 sql(因为它当前使用 bool Approved 并提交审批,但这很脏由于各种原因和需求发生了变化)。
想知道你对此有何想法以及我是否应该选择其中之一。
如果有什么区别的话,我正在使用实体框架。
I have an application which has rows of data in a relation database the table needs a status which will always be either
Not Submitted, Awaiting Approval, Approved, Rejected
Now since these will never change I was trying to decide the best way to implement them I can either think of a Status enum with the values and an int assigned where the int is placed into the status column on the table row.
Or a status table that linked to the table and the user select one of these as the current status.
I can't decide which is the better option as I currently have a enum in place with these values for the approval pages to populate the dropdown etc and setup the sql (as it currently using to bool Approved and submitted for approval but this is dirty for various reasons and needs changed).
Wondering what your thought on this were and whether I should go for one or the other.
If it makes any difference I am using Entity framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果枚举永远不会改变,我会选择它,因为这会提高性能(无需加入即可获取状态)。而且,这是更简单的解决方案:)。
I would go with the Enum if it never changes since this will be more performant (no join to get the status). Also, it's the simpler solution :).
你可以相信这个假设是错误的,而且比你想象的要早。
我会使用查找表。在查找表中添加或更改值比更改枚举的定义要容易得多。
您可以在查找表中使用自然主键,这样您就不需要进行联接来获取值。是的,字符串比整数 id 占用更多空间,但如果您的目标是避免连接,这将实现该目标。
You can count on this assumption being false, and sooner than you think.
I would use a lookup table. It's far easier to add or change values in a lookup table than to change the definition of an enum.
You can use a natural primary key in the lookup table so you don't need to do a join to get the value. Yes a string takes a bit more space than an integer id, but if your goal is to avoid the join this will accomplish that goal.
我使用枚举并使用
[Description("asdf")]
属性来绑定有意义的句子或枚举中不允许的其他内容。然后使用枚举文本本身作为下拉列表中的值,并将描述作为可见文本。I use Enums and use the
[Description("asdf")]
attribute to bind meaningful sentences or other things that aren't allowed in Enums. Then use the Enum text itself as a value in drop downs and the Description as the visible text.