我应该存储在数据库或C#枚举枚举ID /值? [英] Should I store Enum ID/values in the database or a C# enumeration?

查看:208
本文介绍了我应该存储在数据库或C#枚举枚举ID /值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我的数据库表有像用户类型 SalesType 列等。

Say my database tables have columns like UserType, SalesType, etc.

我应该有 UserTypeID userTypeName 数据库表或我应该创建一个C#枚举?

Should I have database tables with UserTypeID, userTypeName or should I just create a C# enumeration?

推荐答案

这有什么错两者兼而有之?如果值的是用户定义或改变,绝对枚举将不适合。

What's wrong with both? If value's are user-defined or changing, definitely enum will not be suitable.

如果值是严格非改变(如性别),你可以让他们为枚举为了便于在应用程序的参考,也是在DB作为单独的表来执行外键和作为参考。

If values are strictly non-changing (such as gender), you can have them as enums for ease of reference in the application and also in the DB as separate table to enforce foreign keys and as a reference.

这篇关于我应该存储在数据库或C#枚举枚举ID /值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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