Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Database-Table-Wrapper Class Code Generator

RSS
Modified on Sat, Oct 20, 2012, 11:13 PM by Administrator Categorized as ASP·NET MVC, Code Generator, SQL Server, ·Net Framework
The following code references the DbLayout view, available here.

with DataTypes as (
    select TSqlType = 'bigint', CsType = 'long'
    union select 'bit', 'bool'
    union select '%char%', 'string'
    union select '%date%', 'DateTime'
    union select 'decimal%', 'decimal'
    union select 'float%', 'decimal'
    union select 'int', 'int'
    union select 'money', 'decimal'
    union select '%text%', 'string'
    union select 'smallint', 'short'
    union select 'uniqueidentifier','Guid'
)
,Fields as (
    select
         CsType = t.CsType + case when d.IsNullable = 1 and t.CsType <> 'string' then '?' else '' end
        ,d.* 
    from dbo.DbLayout d
        left join DataTypes t
            on d.DataType like t.TSqlType
    where 1=1
        and TableName in ('Order', 'Invoice')
    )
select distinct TableName, Sort2 = 10, Sort3 = 10, code = 'public class ' + TableName + 'View' from Fields 
union select distinct TableName, 20, 10, '{' from Fields
union select TableName, 30, ColumnOrder, code = '    public ' + CsType + ' ' + ColumnName + ' { get; set; }' from Fields
union select distinct TableName, 40, 10, '}' from Fields
order by TableName, Sort2, Sort3

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2018, Patrick Jasinski.