﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Cade Bryant / Article Discussions / Article Discussions by Author  / Generate C# class code for table / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 26 May 2013 01:12:01 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Test this free toolCreates classes and SQL CRUD Scriptshttp://rapidshare.com/files/2096091764/ClassCreator%201.0.ziporhttps://skydrive.live.com/#cid=ACCFC2483F700A04&amp;id=ACCFC2483F700A04%2111751</description><pubDate>Sun, 27 Jan 2013 09:35:53 GMT</pubDate><dc:creator>ratxamala</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Free tool in this linkGenerates three tier classes and sql CRUD scriptshttps://skydrive.live.com/#cid=ACCFC2483F700A04&amp;id=ACCFC2483F700A04%2111751orhttp://rapidshare.com/files/2096091764/ClassCreator%201.0.zip</description><pubDate>Mon, 21 Jan 2013 14:51:29 GMT</pubDate><dc:creator>ratxamala</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>nice bit of code, always like being able to have different ways to do stuff. I made my own c# program about a year ago and I use it regularly. It also creates the stored proc to go with the class. Everyone/anyone feel free to download and check it out here:  [url=http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8681&amp;lngWId=10]http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8681&amp;lngWId=10[/url]</description><pubDate>Thu, 06 Sep 2012 19:22:23 GMT</pubDate><dc:creator>cyplesma</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Codesmith [url]http://www.codesmithtools.com[/url] may be a little easier.We use MyGeneration [url]http://www.mygenerationsoftware.com[/url].It is a little dated, but the templates allow scripting in vbscript, VB.Net, or C#.  You can also build forms to pick and choose options for your class as you need them. </description><pubDate>Thu, 06 Sep 2012 06:53:28 GMT</pubDate><dc:creator>charles.byrne</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Even simpler with Auto-Implemented Properties in C# 3.0 and later you don't need the private variable.See [url=http://msdn.microsoft.com/en-us/library/bb384054.aspx][u]http://msdn.microsoft.com/en-us/library/bb384054.aspx[/u][/url]</description><pubDate>Wed, 08 Jun 2011 03:58:10 GMT</pubDate><dc:creator>nigel.</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Good stuff.One minor gripe, you shouldn't be using leading underscores for identifiers. It's generally considered bad practice. </description><pubDate>Wed, 08 Jun 2011 03:50:01 GMT</pubDate><dc:creator>nigel.</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Very handy and free!  Just a couple requests for some sp guru out there:Can anyone modify this to output in VB as well?It would also be nice to change the output of the field names to a different format than what is in the DB.  Example: _firstName instead of _first_name.</description><pubDate>Thu, 30 Jul 2009 18:42:39 GMT</pubDate><dc:creator>swingnchad1</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Greate SP, I modified it to create a function to populate the fields.  You supply the database connectivity part.  Just change the data type of sort on the #tmp table to double, add this:WHEN DATA_TYPE LIKE '%MONEY%' THEN 'double 'to the other switch statements and paste in the following:INSERT INTO @tempSELECT 4.1, '#region Private Method' + CHAR(13) + CHAR(10)INSERT INTO @tempSELECT 4.2, 'private void Load' + @table_name + '(int id)' + CHAR(13) 	+ CHAR(10) + '{' + CHAR(13) + CHAR(10)INSERT INTO @tempSELECT 4.3, 'string sql = "SELECT * FROM ' + @table_name + 	' WHERE   = " + id.ToString();' + CHAR(13) + CHAR(10)INSERT INTO @tempSELECT 4.4, '// Add code to query the database and populate dt' 	+ @table_name + CHAR(13) + CHAR(10)INSERT INTO @tempSELECT 4.5, 'if (dt' + @table_name + '.Rows.Count &amp;gt; 0)' 	+ CHAR(13) + CHAR(10) + '{' + CHAR(13) + CHAR(10) INSERT INTO @tempSELECT 4.6, CASEWHEN DATA_TYPE LIKE '%CHAR%' THEN  'this._' + COLUMN_NAME +	' = dt' + @table_name + '.Rows[0]["' + COLUMN_NAME + '"].ToString();'WHEN DATA_TYPE LIKE '%INT%' THEN 'int.TryParse(dt' + @table_name + 	'.Rows[0]["' + COLUMN_NAME + '"].ToString(), out _' + COLUMN_NAME + ');'WHEN DATA_TYPE LIKE '%DATETIME%' THEN 'DateTime.TryParse(dt' + 	@table_name + '.Rows[0]["' + COLUMN_NAME + '"].ToString(), out _' 	+ COLUMN_NAME + ');'WHEN DATA_TYPE LIKE '%BINARY%' THEN 'this._' + COLUMN_NAME +	' = (byte[])dt' + @table_name + '.Rows[0]["' + COLUMN_NAME + '"];'WHEN DATA_TYPE LIKE '%MONEY%' THEN 'double.TryParse(dt' + @table_name + 	'.Rows[0]["' + COLUMN_NAME + '"].ToString(), out _' + COLUMN_NAME + ');'WHEN DATA_TYPE = 'BIT' THEN 'bool.TryParse(dt' + @table_name + '.Rows[0]["' +	 COLUMN_NAME + '"].ToString().Replace("1", "true").Replace("0", "false"), out _' 	+ COLUMN_NAME + ');'WHEN DATA_TYPE LIKE '%TEXT%' THEN 'this._' + COLUMN_NAME +' = dt' + 	@table_name + '.Rows[0]["' + COLUMN_NAME + '"].ToString();'ELSE 'this._' + COLUMN_NAME +' = dt' + @table_name + '.Rows[0]["' +	 COLUMN_NAME + '"];'END + CHAR(13) + CHAR(10) FROM INFORMATION_SCHEMA.COLUMNSWHERE TABLE_NAME = @table_nameORDER BY ORDINAL_POSITIONINSERT INTO @tempSELECT 4.7, '}' + CHAR(13) + CHAR(10) INSERT INTO @tempSELECT 4.8, '}' + CHAR(13) + CHAR(10)  INSERT INTO @tempSELECT 4.9, '#endregion' + CHAR(13) + CHAR(10)INSERT INTO @tempSELECT 5, '#region Private Fields' + CHAR(13) + CHAR(10)INSERT INTO @tempSELECT 5.1, 'private DataTable dt' + @table_name + ';'+ CHAR(13) + CHAR(10)</description><pubDate>Wed, 16 Apr 2008 10:11:11 GMT</pubDate><dc:creator>TicketNetwork Engineer</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Nicely done.  Thanks.</description><pubDate>Fri, 16 Nov 2007 17:15:45 GMT</pubDate><dc:creator>Dave-148053</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Thanks for this posting. I have modify the script for the case sensitive database, applying the UPPER function to DATATYPE in the CASE WHEN, for each WHEN.Example:WHEN UPPER(DATA_TYPE) LIKE '%CHAR%' THEN 'string 'Maurizio Fazio</description><pubDate>Fri, 16 Nov 2007 10:36:55 GMT</pubDate><dc:creator>Fazio Maurizio</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>I guess it would be easy to add the XML comments required for the public properties to the script. That would make it perfect.</description><pubDate>Fri, 16 Nov 2007 10:00:04 GMT</pubDate><dc:creator>Erzsebet Szabo</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Thanks for this posting. It is great! If you can add other data types such as when data_type like 'uniquidentifier%' then 'Guid 'when data_type in ('money','decimal','float') then 'float ' and so onthen it will be perfect.</description><pubDate>Fri, 16 Nov 2007 08:42:12 GMT</pubDate><dc:creator>Steve S. Yang</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>I agree, generating all these classes is a real drag. Personally, i favour a tool called CodeSmith (www.codesmithtools.com) for this function. It comes with numerous templates but you can also build your own - and though you write the templates using .Net VB/C# the output can be for anything.This means that as well as being able to generate the class for a table, you can generate the basic stored procedures (Get, List, Add, Update, Delete) for the table, and any additional classes you need - at least to a generic level.Where you can get really clever is by setting up your template to point to a new database and generate all the sql and classes for each table in turn......</description><pubDate>Fri, 16 Nov 2007 03:37:50 GMT</pubDate><dc:creator>kma-495907</dc:creator></item><item><title>RE: Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Great Article.</description><pubDate>Fri, 16 Nov 2007 02:58:23 GMT</pubDate><dc:creator>vblllove</dc:creator></item><item><title>Generate C# class code for table</title><link>http://www.sqlservercentral.com/Forums/Topic420651-138-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Development/61477/"&gt;Generate C# class code for table&lt;/A&gt;[/B]</description><pubDate>Fri, 09 Nov 2007 11:35:42 GMT</pubDate><dc:creator>cadebryant</dc:creator></item></channel></rss>