Usuário com melhor resposta
Transformar Campos de uma Tabela em arquivo .CS (em classe) do Visual Studio

Pergunta
-
Respostas
-
Ola, boa tarde.
Catei pela internet encontrei duas formas interessantes:
ou você pode customizar esse T-SQL
declare @TableName sysname = 'TableName' declare @result varchar(max) = 'public class ' + @TableName + ' {' select @result = @result + ' public ' + ColumnType + ' ' + ColumnName + ' { get; set; } ' from ( select replace(col.name, ' ', '_') ColumnName, column_id, 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' end ColumnType from sys.columns col join sys.types typ on col.system_type_id = typ.system_type_id where object_id = object_id(@TableName) ) t order by column_id set @result = @result + ' }' print @result
Link original http://stackoverflow.com/questions/5873170/generate-class-from-database-table
Na empresa onde trabalha, tínhamos criado um aplicativo interno via reflection que fazia isso, mas não tenho acesso mais.
;) até mais.
Altieri Pereira http://altieripereira.blogspot.com/
- Marcado como Resposta Ricardo Soares Nogueira quinta-feira, 16 de janeiro de 2014 18:44
Todas as Respostas
-
Ola, boa tarde.
Catei pela internet encontrei duas formas interessantes:
ou você pode customizar esse T-SQL
declare @TableName sysname = 'TableName' declare @result varchar(max) = 'public class ' + @TableName + ' {' select @result = @result + ' public ' + ColumnType + ' ' + ColumnName + ' { get; set; } ' from ( select replace(col.name, ' ', '_') ColumnName, column_id, 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' end ColumnType from sys.columns col join sys.types typ on col.system_type_id = typ.system_type_id where object_id = object_id(@TableName) ) t order by column_id set @result = @result + ' }' print @result
Link original http://stackoverflow.com/questions/5873170/generate-class-from-database-table
Na empresa onde trabalha, tínhamos criado um aplicativo interno via reflection que fazia isso, mas não tenho acesso mais.
;) até mais.
Altieri Pereira http://altieripereira.blogspot.com/
- Marcado como Resposta Ricardo Soares Nogueira quinta-feira, 16 de janeiro de 2014 18:44
-
-