Note that there are some explanatory texts on larger screens.

plurals
  1. POSubSonic 3.0.0.3 | SimpleRepository | DB DataType - Class DataType mapping
    primarykey
    data
    text
    <p>I am beginning to make friends with SubSonic 3.0.0.3 - SimpleRepository. Since you/I have to create every object class, so I made a simple code below, just to save some time.</p> <p>My only question is, does my mapping are correct (DB DataType to .Net DataType)?</p> <p><strong>Here's the simple code:</strong></p> <pre><code>public string CreateClassEntity(string ConnectionSring, string TableName) { SqlDatabase db = new SqlDatabase(ConnectionSring); string sqlCommand = "SELECT TOP 1 * FROM " + TableName + ""; DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); DataSet subsonicDataSet = db.ExecuteDataSet(dbCommand); DataTable subsonicDataTable = subsonicDataSet.Tables[0].Clone(); string classEntity = "public class " + TableName + " \n{"; foreach(DataColumn column in subsonicDataTable.Columns) { classEntity += "\n\tpublic "; classEntity += column.DataType.ToString().Replace("System.", string.Empty) + " "; classEntity += column.ColumnName + " "; classEntity += "{ get; set; }"; } classEntity += "\n}"; return classEntity; } </code></pre> <p><strong>Sample target Table (SQL 2008):</strong></p> <pre><code>CREATE TABLE [kiss].[Users]( [ID] [int] IDENTITY(1,1) NOT NULL, [UserName] [nvarchar](20) NOT NULL, [UserPassword] [varbinary](128) NULL, [UserTypeID] [tinyint] NOT NULL, [ByPassAccessRestrictionsFlag] [bit] NOT NULL, [IsEnforcePasswordPolicy] [bit] NOT NULL, [PasswordExpirationDate] [datetime] NULL, [IsPwdChangeNextLogin] [bit] NOT NULL, [ShowLatestNewsFlag] [bit] NOT NULL, [SortRowNumber] [int] NOT NULL, [CreatedDate] [datetime] NOT NULL, [CreatedBy] [nvarchar](20) NOT NULL, [UpdatedDate] [datetime] NOT NULL, [UpdatedBy] [nvarchar](20) NOT NULL, [DeletedDate] [int] NULL, [EntityTypeID] [int] NOT NULL ) </code></pre> <p><strong>Sample Class Output:</strong></p> <pre><code>public class Users { public Int32 ID { get; set; } public String UserName { get; set; } public Byte[] UserPassword { get; set; } public Byte UserTypeID { get; set; } public Boolean ByPassAccessRestrictionsFlag { get; set; } public Boolean IsEnforcePasswordPolicy { get; set; } public DateTime PasswordExpirationDate { get; set; } public Boolean IsPwdChangeNextLogin { get; set; } public Boolean ShowLatestNewsFlag { get; set; } public Int32 SortRowNumber { get; set; } public DateTime CreatedDate { get; set; } public String CreatedBy { get; set; } public DateTime UpdatedDate { get; set; } public String UpdatedBy { get; set; } public Int32 DeletedDate { get; set; } public Int32 EntityTypeID { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload