SQL Table to C# Class_Tabloyu Class'a çevirme
<blockquote> <p>declare @TableName sysname = 'LG_003_03_STLINE'<br /> declare @Result varchar(max) = 'public class ' + @TableName + '<br /> {'</p> <p>select @Result = @Result + '<br /> public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }<br /> '<br /> from<br /> (<br /> select <br /> replace(col.name, ' ', '_') ColumnName,<br /> column_id ColumnId,<br /> case typ.name <br /> when 'bigint' then 'long'<br /> when 'binary' then 'byte[]'<br /> when 'bit' then 'bool'<br /> when 'char' then 'string'<br /> when 'date' then 'DateTime'<br /> when 'datetime' then 'DateTime'<br /> when 'datetime2' then 'DateTime'<br /> when 'datetimeoffset' then 'DateTimeOffset'<br /> when 'decimal' then 'decimal'<br /> when 'float' then 'double'<br /> when 'image' then 'byte[]'<br /> when 'int' then 'int'<br /> when 'money' then 'decimal'<br /> when 'nchar' then 'string'<br /> when 'ntext' then 'string'<br /> when 'numeric' then 'decimal'<br /> when 'nvarchar' then 'string'<br /> when 'real' then 'float'<br /> when 'smalldatetime' then 'DateTime'<br /> when 'smallint' then 'short'<br /> when 'smallmoney' then 'decimal'<br /> when 'text' then 'string'<br /> when 'time' then 'TimeSpan'<br /> when 'timestamp' then 'long'<br /> when 'tinyint' then 'byte'<br /> when 'uniqueidentifier' then 'Guid'<br /> when 'varbinary' then 'byte[]'<br /> when 'varchar' then 'string'<br /> else 'UNKNOWN_' + typ.name<br /> end ColumnType,<br /> case <br /> 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') <br /> then '?' <br /> else '' <br /> end NullableSign<br /> from sys.columns col<br /> join sys.types typ on<br /> col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id<br /> where object_id = object_id(@TableName)<br /> ) t<br /> order by ColumnId</p> <p>set @Result = @Result + '<br /> }'</p> <p>print @Result</p> </blockquote>
0 Yorum