One of the most tedious parts of developing database-driven application is coding the wrapper classes for your database objects. This is especially true if you are dealing with a database containing a large number of tables, or tables with many columns.
My proc, usp_TableToClass, can make this task much easier and less time-consuming. For any table name passed in as an argument, it generates the complete core of a C# class file corresponding to the table - including a parameterless constructor, private fields, and public properties with getters and setters.
As a very simple example, suppose we have the following table:
CREATE TABLE Contact
(
FirstName VARCHAR(128),
LastName VARCHAR(128),
Address VARCHAR(256)
)
GO
By running the following:
EXEC usp_TableToClass 'Contact'
The following class code gets generated:
public class Contact
{
#region Constructors
public Contact()
{
}
#endregion
#region Private Fields
private string _FirstName;
private string _LastName;
private string _Address;
#endregion
#region Public Properties
public string FirstName
{
get { return _FirstName; }
set { _FirstName = value; }
}
public string LastName
{
get { return _LastName; }
set { _LastName = value; }
}
public string Address
{
get { return _Address; }
set { _Address = value; }
}
#endregion
}