Created
November 9, 2016 23:29
-
-
Save vgerbase/8c8ab48e67a4fcc65399e0f1ee65b9db to your computer and use it in GitHub Desktop.
Generate class properties from table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| 'public ' | |
| + CASE | |
| WHEN c.DATA_TYPE IN ('bigint') THEN 'long' | |
| WHEN c.DATA_TYPE IN ('int') THEN 'int' | |
| WHEN c.DATA_TYPE IN ('smallint') THEN 'short' | |
| WHEN c.DATA_TYPE IN ('tinyint') THEN 'byte' | |
| WHEN c.DATA_TYPE IN ('decimal', 'numeric', 'smallmoney', 'money') THEN 'decimal' | |
| WHEN c.DATA_TYPE IN ('real') THEN 'single' | |
| WHEN c.DATA_TYPE IN ('float', 'decimal') THEN 'double' | |
| WHEN c.DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'text', 'ntext') THEN 'string' | |
| WHEN c.DATA_TYPE IN ('smalldatetime', 'datetime', 'datetime2', 'date') THEN 'DateTime' | |
| WHEN c.DATA_TYPE IN ('time') THEN 'TimeSpan' | |
| WHEN c.DATA_TYPE IN ('datetimeoffset') THEN 'DateTimeOffset' | |
| WHEN c.DATA_TYPE IN ('bit') THEN 'bool' | |
| WHEN c.DATA_TYPE IN ('uniqueidentifier') THEN 'Guid' | |
| WHEN c.DATA_TYPE IN ('binary', 'varbinary', 'image', 'timestamp', 'rowversion') THEN 'byte[]' | |
| WHEN c.DATA_TYPE IN ('xml') THEN 'Xml' | |
| END | |
| + CASE | |
| WHEN c.IS_NULLABLE = 'YES' AND c.DATA_TYPE <> 'varchar' THEN '? ' | |
| ELSE ' ' | |
| END | |
| + c.COLUMN_NAME + ' { get; set; }' | |
| FROM information_schema.columns c | |
| WHERE c.table_name = 'Premio' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment