Last active
August 29, 2015 14:14
-
-
Save kmoormann/d6e46680ef75d90e2855 to your computer and use it in GitHub Desktop.
C# Dto Builder Based On Information Schema
This file contains 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
DECLARE @tableName VARCHAR(50) = 'Foo' | |
SELECT | |
'public ' | |
+ CASE | |
WHEN DATA_TYPE = 'int' THEN 'int' | |
WHEN DATA_TYPE = 'uniqueidentifier' THEN 'Guid' | |
WHEN DATA_TYPE = 'nvarchar' THEN 'string' | |
WHEN DATA_TYPE = 'datetime' THEN 'DateTime' | |
WHEN DATA_TYPE = 'bit' THEN 'bool' | |
WHEN DATA_TYPE = 'decimal' THEN 'decimal' | |
ELSE DATA_TYPE | |
END | |
+ CASE WHEN (IS_NULLABLE = 'YES' AND DATA_TYPE <> 'nvarchar') THEN '?' | |
ELSE '' | |
END | |
+ ' ' | |
+ COLUMN_NAME | |
+ ' { get; set; }' | |
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @tableName | |
ORDER BY ORDINAL_POSITION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment