public ProfileThumbnailData Load(ISqlConnectionInfo connection, SqlQueryParameters parameters)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT {0} " +
                             ProfileThumbnailDataTable.GetColumnNames("[ptd]") +
                             (this.Depth > 0 ? "," + ProfileThumbnailTable.GetColumnNames("[ptd_pt]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProfileTable.GetColumnNames("[ptd_pt_p]") : string.Empty) +
                             " FROM [web].[ProfileThumbnailData] AS [ptd] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileThumbnail] AS [ptd_pt] ON [ptd].[ProfileThumbnailID] = [ptd_pt].[ProfileThumbnailID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [web].[Profile] AS [ptd_pt_p] ON [ptd_pt].[ProfileID] = [ptd_pt_p].[ProfileID] ";
                }


                parameters.Top = 1;
                sqlCmdText     = parameters.BuildQuery(sqlCmdText);
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                foreach (KeyValuePair <string, object> argument in parameters.Arguments)
                {
                    sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value);
                }

                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "customload", "notfound"), "ProfileThumbnailData could not be loaded using custom logic as it was not found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ProfileThumbnailDataTable ptdTable    = new ProfileThumbnailDataTable(query);
                ProfileThumbnailTable     ptd_ptTable = (this.Depth > 0) ? new ProfileThumbnailTable(query) : null;
                ProfileTable ptd_pt_pTable            = (this.Depth > 1) ? new ProfileTable(query) : null;


                Profile              ptd_pt_pObject = (this.Depth > 1) ? ptd_pt_pTable.CreateInstance() : null;
                ProfileThumbnail     ptd_ptObject   = (this.Depth > 0) ? ptd_ptTable.CreateInstance(ptd_pt_pObject) : null;
                ProfileThumbnailData ptdObject      = ptdTable.CreateInstance(ptd_ptObject);
                sqlReader.Close();

                return(ptdObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "customload", "exception"), "ProfileThumbnailData could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "ProfileThumbnailData", "Exception while loading (custom/single) ProfileThumbnailData object from database. See inner exception for details.", ex);
            }
        }
        protected override ProfileThumbnailData LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             ProfileThumbnailDataTable.GetColumnNames("[ptd]") +
                             (this.Depth > 0 ? "," + ProfileThumbnailTable.GetColumnNames("[ptd_pt]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProfileTable.GetColumnNames("[ptd_pt_p]") : string.Empty) +
                             " FROM [web].[ProfileThumbnailData] AS [ptd] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileThumbnail] AS [ptd_pt] ON [ptd].[ProfileThumbnailID] = [ptd_pt].[ProfileThumbnailID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [web].[Profile] AS [ptd_pt_p] ON [ptd_pt].[ProfileID] = [ptd_pt_p].[ProfileID] ";
                }
                sqlCmdText += "WHERE [ptd].[ProfileThumbnailDataID] = @ProfileThumbnailDataID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@ProfileThumbnailDataID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "loadinternal", "notfound"), "ProfileThumbnailData could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ProfileThumbnailDataTable ptdTable    = new ProfileThumbnailDataTable(query);
                ProfileThumbnailTable     ptd_ptTable = (this.Depth > 0) ? new ProfileThumbnailTable(query) : null;
                ProfileTable ptd_pt_pTable            = (this.Depth > 1) ? new ProfileTable(query) : null;


                Profile              ptd_pt_pObject = (this.Depth > 1) ? ptd_pt_pTable.CreateInstance() : null;
                ProfileThumbnail     ptd_ptObject   = (this.Depth > 0) ? ptd_ptTable.CreateInstance(ptd_pt_pObject) : null;
                ProfileThumbnailData ptdObject      = ptdTable.CreateInstance(ptd_ptObject);
                sqlReader.Close();

                return(ptdObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "loadinternal", "exception"), "ProfileThumbnailData could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "ProfileThumbnailData", "Exception while loading ProfileThumbnailData object from database. See inner exception for details.", ex);
            }
        }