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.
由于这些不会改变,所以我试图确定实现它们的最佳方式,我可以考虑使用值的状态枚举和将int放在表行的状态列中指定的int类型。
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).
我不能决定哪个是更好的选择,因为我目前有一个枚举这些值的批准页填充下拉等和设置sql(目前使用bool批准并提交审批,但因各种原因这是肮脏的,需要改变)。
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.
如果有什么不同,我正在使用实体框架。
3 个解决方案
#1
1
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 :).
如果它永远不变,我就会选择Enum,因为它将具有更强的性能(没有join来获得状态)。而且,它是更简单的解决方案:)。
#2
1
Now since these will never change...
既然这些永远不会改变……
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.
您可以在查找表中使用一个自然的主键,因此不需要进行连接来获取值。是的,字符串需要比整数id多一点的空间,但是如果您的目标是避免连接,那么这将实现这个目标。
#3
1
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.
我使用enum并使用[Description("asdf")]属性来绑定有意义的句子或其他在enum中不允许的内容。然后将Enum文本本身用作下拉列表中的值,将Description作为可见文本。
#1
1
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 :).
如果它永远不变,我就会选择Enum,因为它将具有更强的性能(没有join来获得状态)。而且,它是更简单的解决方案:)。
#2
1
Now since these will never change...
既然这些永远不会改变……
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.
您可以在查找表中使用一个自然的主键,因此不需要进行连接来获取值。是的,字符串需要比整数id多一点的空间,但是如果您的目标是避免连接,那么这将实现这个目标。
#3
1
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.
我使用enum并使用[Description("asdf")]属性来绑定有意义的句子或其他在enum中不允许的内容。然后将Enum文本本身用作下拉列表中的值,将Description作为可见文本。