zoukankan      html  css  js  c++  java
  • 从数据库表生成类

    DECLARE @TableName sysname = 'T_Location';
    DECLARE @Result VARCHAR(MAX) = 'public class ' + @TableName + '
    {';
    SELECT @Result = @Result + '
        /// <summary>
        /// '        + CAST(t.Summary AS VARCHAR(MAX)) + '
        /// </summary>
        public '     + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }
    '
    FROM
    (
        SELECT REPLACE(col.name, ' ', '_') ColumnName,
               col.column_id ColumnId,
               CASE typ.name
                   WHEN 'bigint' THEN
                       'long'
                   WHEN 'binary' THEN
                       'byte[]'
                   WHEN 'bit' THEN
                       'bool'
                   WHEN 'char' THEN
                       'string'
                   WHEN 'date' THEN
                       'DateTime'
                   WHEN 'datetime' THEN
                       'DateTime'
                   WHEN 'datetime2' THEN
                       'DateTime'
                   WHEN 'datetimeoffset' THEN
                       'DateTimeOffset'
                   WHEN 'decimal' THEN
                       'decimal'
                   WHEN 'float' THEN
                       'float'
                   WHEN 'image' THEN
                       'byte[]'
                   WHEN 'int' THEN
                       'int'
                   WHEN 'money' THEN
                       'decimal'
                   WHEN 'nchar' THEN
                       'char'
                   WHEN 'ntext' THEN
                       'string'
                   WHEN 'numeric' THEN
                       'decimal'
                   WHEN 'nvarchar' THEN
                       'string'
                   WHEN 'real' THEN
                       'double'
                   WHEN 'smalldatetime' THEN
                       'DateTime'
                   WHEN 'smallint' THEN
                       'short'
                   WHEN 'smallmoney' THEN
                       'decimal'
                   WHEN 'text' THEN
                       'string'
                   WHEN 'time' THEN
                       'TimeSpan'
                   WHEN 'timestamp' THEN
                       'DateTime'
                   WHEN 'tinyint' THEN
                       'byte'
                   WHEN 'uniqueidentifier' THEN
                       'Guid'
                   WHEN 'varbinary' THEN
                       'byte[]'
                   WHEN 'varchar' THEN
                       'string'
                   ELSE
                       'UNKNOWN_' + typ.name
               END ColumnType,
               CASE
                   WHEN col.is_nullable = 1
                        AND typ.name IN ( 'bigint', 'bit', 'date', 'datetime', 'datetime2', 'datetimeoffset', 'decimal',
                                          'float', 'int', 'money', 'numeric', 'real', 'smalldatetime', 'smallint',
                                          'smallmoney', 'time', 'tinyint', 'uniqueidentifier','string'
                                        ) THEN
                       '?'
                   ELSE
                       ''
               END NullableSign,
               ISNULL(ep.value, col.name) AS Summary
        FROM sys.columns col
            JOIN sys.types typ
                ON col.system_type_id = typ.system_type_id
                   AND col.user_type_id = typ.user_type_id
            LEFT JOIN sys.extended_properties ep
                ON ep.major_id = col.object_id
                   AND ep.minor_id = col.column_id
        WHERE col.object_id = OBJECT_ID(@TableName)
    ) t
    ORDER BY ColumnId;
    SET @Result = @Result + '
    }';
    PRINT @Result;
  • 相关阅读:
    处理键盘弹出
    纯手码自动布局
    ios 随机色 宏定义
    linux下自定义pid实现任意数据采集
    http://blog.chinaunix.net/uid-9845710-id-1996675.html snmpd配置
    http://www.360doc.com/content/10/0928/12/11991_57014502.shtml
    pingall脚本
    http://lihuipeng.blog.51cto.com/3064864/643960
    elf 文件
    php中获取周几的方法
  • 原文地址:https://www.cnblogs.com/wfy680/p/15522679.html
Copyright © 2011-2022 走看看