public RouteParameter 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} " +
                             RouteParameterTable.GetColumnNames("[rp]") +
                             (this.Depth > 0 ? "," + RouteTable.GetColumnNames("[rp_r]") : string.Empty) +
                             (this.Depth > 1 ? "," + RouteSetTable.GetColumnNames("[rp_r_rs]") : string.Empty) +
                             " FROM [core].[RouteParameter] AS [rp] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Route] AS [rp_r] ON [rp].[RouteID] = [rp_r].[RouteID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[RouteSet] AS [rp_r_rs] ON [rp_r].[RouteSetID] = [rp_r_rs].[RouteSetID] ";
                }


                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("rp", "customload", "notfound"), "RouteParameter 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);

                RouteParameterTable rpTable      = new RouteParameterTable(query);
                RouteTable          rp_rTable    = (this.Depth > 0) ? new RouteTable(query) : null;
                RouteSetTable       rp_r_rsTable = (this.Depth > 1) ? new RouteSetTable(query) : null;


                RouteSet       rp_r_rsObject = (this.Depth > 1) ? rp_r_rsTable.CreateInstance() : null;
                Route          rp_rObject    = (this.Depth > 0) ? rp_rTable.CreateInstance(rp_r_rsObject) : null;
                RouteParameter rpObject      = rpTable.CreateInstance(rp_rObject);
                sqlReader.Close();

                return(rpObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rp", "customload", "exception"), "RouteParameter 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, "RouteParameter", "Exception while loading (custom/single) RouteParameter object from database. See inner exception for details.", ex);
            }
        }
        protected override RouteParameter 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 " +
                             RouteParameterTable.GetColumnNames("[rp]") +
                             (this.Depth > 0 ? "," + RouteTable.GetColumnNames("[rp_r]") : string.Empty) +
                             (this.Depth > 1 ? "," + RouteSetTable.GetColumnNames("[rp_r_rs]") : string.Empty) +
                             " FROM [core].[RouteParameter] AS [rp] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Route] AS [rp_r] ON [rp].[RouteID] = [rp_r].[RouteID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[RouteSet] AS [rp_r_rs] ON [rp_r].[RouteSetID] = [rp_r_rs].[RouteSetID] ";
                }
                sqlCmdText += "WHERE [rp].[RouteParameterID] = @RouteParameterID;";

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

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rp", "loadinternal", "notfound"), "RouteParameter 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);

                RouteParameterTable rpTable      = new RouteParameterTable(query);
                RouteTable          rp_rTable    = (this.Depth > 0) ? new RouteTable(query) : null;
                RouteSetTable       rp_r_rsTable = (this.Depth > 1) ? new RouteSetTable(query) : null;


                RouteSet       rp_r_rsObject = (this.Depth > 1) ? rp_r_rsTable.CreateInstance() : null;
                Route          rp_rObject    = (this.Depth > 0) ? rp_rTable.CreateInstance(rp_r_rsObject) : null;
                RouteParameter rpObject      = rpTable.CreateInstance(rp_rObject);
                sqlReader.Close();

                return(rpObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rp", "loadinternal", "exception"), "RouteParameter 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, "RouteParameter", "Exception while loading RouteParameter object from database. See inner exception for details.", ex);
            }
        }