[英]How to get data in enum from database instant of stastically typed data? in asp.net core mvc
Dept.cs部门
public enum Dept
{
None,
HR,
IT,
Payroll
}
above Dept enum data is already typed but want fetch data from database in this enum using asp.net core mvc上面的部门枚举数据已经输入,但想要使用asp.net core mvc 从这个枚举中的数据库中获取数据
Model Department.cs模型部.cs
public class Department
{
public int DeptId { get; set; }
public string DeptName { get; set; }
}
You can't change the value of an enum
member.您不能更改
enum
成员的值。 Enums are, by definition, groups of constants - which means that the values of their members is set at compile time and can't be changed.根据定义,枚举是一组常量——这意味着它们的成员的值是在编译时设置的,不能更改。
From the Enumeration types (C# reference) page on Microsoft Docs:从 Microsoft Docs 上的枚举类型(C# 参考)页面:
An enumeration type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type.
枚举类型(或枚举类型)是由一组底层整数类型的命名常量定义的值类型。
This is why using Database data as enums is a bad idea - once the database data has changed, you'll need to change your code as well, recompile and redistribute it.这就是为什么使用数据库数据作为枚举是一个坏主意 - 一旦数据库数据发生变化,您也需要更改代码,重新编译并重新分发它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.