如何在MS SQL Server 2014中创建新的数据类型?

时间:2016-03-09 13:44:14

标签: c# sql-server tsql

在我的应用程序的服务器端,我使用MS SQL Server 2014 Express。在客户端,我有C#WPF应用程序,我在那里有以下枚举类型:

/// <summary>
/// User authorization level.
/// </summary>
public enum UserAuthorizationLevel
{
    /// <summary>
    /// Only visual inspection is allowed (the first lower level).
    /// </summary>
    Inspection,
    /// <summary>
    /// Some settings in apparatus are allowed (the second level).
    /// </summary>
    SettingDeviceParametersApplied,
    /// <summary>
    /// Some more setting in apparatus are allowed than in the second level (the third level).
    /// </summary>
    Maintenance,
    /// <summary>
    /// Apparatus manufacturer level - full access is allowed (the highest level).
    /// </summary>
    Manufacturer
}

我可以在服务器端(在MS SQL Server数据库中)创建此类型,并将此类型用作数据库表中字段的类型吗?

1 个答案:

答案 0 :(得分:0)

我建议你看一下:Best method to store Enum in Database

你拥有的是一个Enum,而不是一个类型。枚举转换为Int类型。所以你会有这样的事情:

/// <summary>
/// User authorization level.
/// </summary>
public enum UserAuthorizationLevel
{
    /// <summary>
    /// Only visual inspection is allowed (the first lower level).
    /// </summary>
    Inspection = 0,
    /// <summary>
    /// Some settings in apparatus are allowed (the second level).
    /// </summary>
    SettingDeviceParametersApplied = 1,
    /// <summary>
    /// Some more setting in apparatus are allowed than in the second level (the third level).
    /// </summary>
    Maintenance = 2,
    /// <summary>
    /// Apparatus manufacturer level - full access is allowed (the highest level).
    /// </summary>
    Manufacturer = 3
}