<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Generate_Entity_from_Data_Table</id>
		<title>Generate Entity from Data Table - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Generate_Entity_from_Data_Table"/>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Generate_Entity_from_Data_Table&amp;action=history"/>
		<updated>2026-10-28T06:04:24Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://logicwiki.co.uk/index.php?title=Generate_Entity_from_Data_Table&amp;diff=2211&amp;oldid=prev</id>
		<title>AliIybar: Created page with &quot;Category:EntityFramework Category:MsSQL Category:Dotnet  Change the &quot;TableName&quot; to the table name you want to generate class from.  &lt;pre&gt; declare @TableName sysnam...&quot;</title>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Generate_Entity_from_Data_Table&amp;diff=2211&amp;oldid=prev"/>
				<updated>2021-10-04T09:25:49Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/index.php?title=Category:EntityFramework&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:EntityFramework (page does not exist)&quot;&gt;Category:EntityFramework&lt;/a&gt; &lt;a href=&quot;/index.php?title=Category:MsSQL&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:MsSQL (page does not exist)&quot;&gt;Category:MsSQL&lt;/a&gt; &lt;a href=&quot;/index.php?title=Category:Dotnet&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Dotnet (page does not exist)&quot;&gt;Category:Dotnet&lt;/a&gt;  Change the &amp;quot;TableName&amp;quot; to the table name you want to generate class from.  &amp;lt;pre&amp;gt; declare @TableName sysnam...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:EntityFramework]]&lt;br /&gt;
[[Category:MsSQL]]&lt;br /&gt;
[[Category:Dotnet]]&lt;br /&gt;
&lt;br /&gt;
Change the &amp;quot;TableName&amp;quot; to the table name you want to generate class from.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare @TableName sysname = 'TableName'&lt;br /&gt;
declare @Result varchar(max) = 'public class ' + @TableName + '&lt;br /&gt;
{'&lt;br /&gt;
&lt;br /&gt;
select @Result = @Result + '&lt;br /&gt;
    public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }&lt;br /&gt;
'&lt;br /&gt;
from&lt;br /&gt;
(&lt;br /&gt;
    select &lt;br /&gt;
        replace(col.name, ' ', '_') ColumnName,&lt;br /&gt;
        column_id ColumnId,&lt;br /&gt;
        case typ.name &lt;br /&gt;
            when 'bigint' then 'long'&lt;br /&gt;
            when 'binary' then 'byte[]'&lt;br /&gt;
            when 'bit' then 'bool'&lt;br /&gt;
            when 'char' then 'string'&lt;br /&gt;
            when 'date' then 'DateTime'&lt;br /&gt;
            when 'datetime' then 'DateTime'&lt;br /&gt;
            when 'datetime2' then 'DateTime'&lt;br /&gt;
            when 'datetimeoffset' then 'DateTimeOffset'&lt;br /&gt;
            when 'decimal' then 'decimal'&lt;br /&gt;
            when 'float' then 'double'&lt;br /&gt;
            when 'image' then 'byte[]'&lt;br /&gt;
            when 'int' then 'int'&lt;br /&gt;
            when 'money' then 'decimal'&lt;br /&gt;
            when 'nchar' then 'string'&lt;br /&gt;
            when 'ntext' then 'string'&lt;br /&gt;
            when 'numeric' then 'decimal'&lt;br /&gt;
            when 'nvarchar' then 'string'&lt;br /&gt;
            when 'real' then 'float'&lt;br /&gt;
            when 'smalldatetime' then 'DateTime'&lt;br /&gt;
            when 'smallint' then 'short'&lt;br /&gt;
            when 'smallmoney' then 'decimal'&lt;br /&gt;
            when 'text' then 'string'&lt;br /&gt;
            when 'time' then 'TimeSpan'&lt;br /&gt;
            when 'timestamp' then 'long'&lt;br /&gt;
            when 'tinyint' then 'byte'&lt;br /&gt;
            when 'uniqueidentifier' then 'Guid'&lt;br /&gt;
            when 'varbinary' then 'byte[]'&lt;br /&gt;
            when 'varchar' then 'string'&lt;br /&gt;
            else 'UNKNOWN_' + typ.name&lt;br /&gt;
        end ColumnType,&lt;br /&gt;
        case &lt;br /&gt;
            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') &lt;br /&gt;
            then '?' &lt;br /&gt;
            else '' &lt;br /&gt;
        end NullableSign&lt;br /&gt;
    from sys.columns col&lt;br /&gt;
        join sys.types typ on&lt;br /&gt;
            col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id&lt;br /&gt;
    where object_id = object_id(@TableName)&lt;br /&gt;
) t&lt;br /&gt;
order by ColumnId&lt;br /&gt;
&lt;br /&gt;
set @Result = @Result  + '&lt;br /&gt;
}'&lt;br /&gt;
&lt;br /&gt;
print @Result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>AliIybar</name></author>	</entry>

	</feed>