数据库库设计:字典表的设计

来源:互联网 发布:知乎一小时 mobi 编辑:程序博客网 时间:2024/06/06 09:48

在设计软件时,经常会遇到类型的问题,也就是分类问题,例如:员工分类,正式员工,试用员工,实习生。这些数据是设计成字典表还是设计成常量?

  在我们的系统中一直是设计成表的,但由于系统中有很多有很多中这种类型,导致很多表只有不到四五条数据,数据几乎不变,为了展示,使用视图,使用表关联。

   其实我感觉像这样几乎不变的数据,设计成常量,应该更好,性能好,修改也简单,要改成表也很方便,相反如果是表要改成常量就困难了,尤其是使用了大量视图为了展示。

如果以后为了性能优化,还可以生成js脚本,生成JS对象,加快处理速度。

设计实例

  public class EmployeeType    {        public const  int Trial = 0;        public const int Official = 1;               public const int Internship = 2;        /// <summary>        /// 用于展示        /// </summary>        /// <param name="type"></param>        /// <returns></returns>        public static  string GetText(int type)        {            string text="";            switch (type)            {                case Trial:                    text = "试用";                    break;                case Official:                    text = "正式";                    break;                case Internship:                    text = "实习";                    break;                default:                    text = "未定义";                    break;            }            return text;        }        /// <summary>        /// 用于下拉        /// </summary>        /// <param name="type"></param>        /// <returns></returns>        public static List<DropListItem> GetDropList(int type)        {            List<DropListItem> list = new List<DropListItem>();            list.Add(new DropListItem()            {                Value = Trial,                Text = GetText(Trial)// "试用"            }             );            list.Add(new DropListItem()            {                Value = Official,                Text = GetText(Official)            }            );            list.Add(new DropListItem()            {                Value = Internship,                Text = GetText(Internship)            }            );            return list;        }    }    public class DropListItem    {        public int Value { set; get; }        public string Text { set; get; }    }





0 1
原创粉丝点击