declare @TableName sysname = 'checkDate'--我的表名 SELECT 'private '+ case [Types].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_' + [Types].name end +' _'+ [Columns].name+';' FROM sys.tables AS [Tables] INNER JOIN sys.columns AS [Columns] ON [Tables].object_id = [Columns].object_id INNER JOIN sys.types AS [Types] ON [Columns].system_type_id = [Types].system_type_id AND is_user_defined = 0 AND [Types].name <> 'sysname' LEFT OUTER JOIN sys.extended_properties AS [Properties] ON [Properties].major_id = [Tables].object_id AND [Properties].minor_id = [Columns].column_id AND [Properties].name = 'MS_Description' WHERE [Tables].name =@TableName ORDER BY [Columns].column_id -----------------------------------------------私有实体------------------------------------------------- declare @Result varchar(max) = ' /// <summary> /// ' + @TableName + ' /// </summary> public class ' + @TableName + ' {' select @Result = @Result + ' /// <summary> /// ' + CONVERT(NVARCHAR(500), ISNULL(ColName, '无')) + ' /// </summary> public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get{return _'+ColumnName+';} set{_'+ColumnName+'=value;} }' from ( SELECT replace(col.name, ' ', '_') ColumnName, column_id ColumnId, prop.value ColName, 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') then '?' else '' end NullableSign 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 prop ON col.object_id = prop.major_id AND col.column_id = prop.minor_id where object_id = object_id(@TableName) ) t --order by ColumnId set @Result = @Result + ' }' print @Result -----------查询结果---------- private int _sid;private int _suid; /// <summary>/// checkDate /// </summary>public class checkDate{ /// <summary> /// 主键 /// </summary> public int sid { get{return _sid;} set{_sid=value;} } /// <summary> /// 用户id /// </summary> public int suid { get{return _suid;} set{_suid=value;} }}
SQL Server 生成C#公共实体属性和私有属性
来源:这里教程网
时间:2026-03-02 12:06:15
作者:
编辑推荐:
- SQL Server 生成C#公共实体属性和私有属性03-02
- 设置SQLserver运行内存03-02
- CMD 执行大文件SQL脚本03-02
- 天九集团:责任型创新促进共赢03-02
- 杏悦2主管2540437[20201208]为什么返回2行记录补充.txt03-02
- 查询SQLServer的客户端IP和主机名03-02
- Sqlserver查询alwayson同步情况脚本(2)03-02
- SQLServer中如何删除字段的自增标识03-02
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- 天九集团:责任型创新促进共赢
天九集团:责任型创新促进共赢
26-03-02 - Sqlserver查询alwayson同步情况脚本(2)
Sqlserver查询alwayson同步情况脚本(2)
26-03-02 - 把TXT文本导入SQLServer 出错:数据转换失败
把TXT文本导入SQLServer 出错:数据转换失败
26-03-02 - SQLServer开启CDC功能(1)
SQLServer开启CDC功能(1)
26-03-02 - SQL Server数据库mdf文件中了勒索病毒*.mdf.ReadInstructions
- 统信UOS共享文件夹权限密码设置方法图解教程
统信UOS共享文件夹权限密码设置方法图解教程
26-03-02 - SQLServer导入大CSV文件
SQLServer导入大CSV文件
26-03-02 - SQLServer DBA 三十问
SQLServer DBA 三十问
26-03-02 - 支撑2715亿元海量订单 揭秘京东大促背后的数据库基石
支撑2715亿元海量订单 揭秘京东大促背后的数据库基石
26-03-02 - SQLServer内存问题分析
SQLServer内存问题分析
26-03-02
