Example #1
0
        protected override MOMessage 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 " +
                             MOMessageTable.GetColumnNames("[mom]") +
                             (this.Depth > 0 ? "," + MessageTable.GetColumnNames("[mom_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[mom_m_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + CustomerTable.GetColumnNames("[mom_m_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + MobileOperatorTable.GetColumnNames("[mom_m_mo]") : string.Empty) +
                             " FROM [stats].[MOMessage] AS [mom] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [stats].[Message] AS [mom_m] ON [mom].[MessageID] = [mom_m].[MessageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Service] AS [mom_m_s] ON [mom_m].[ServiceID] = [mom_m_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Customer] AS [mom_m_c] ON [mom_m].[CustomerID] = [mom_m_c].[CustomerID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [mom_m_mo] ON [mom_m].[MobileOperatorID] = [mom_m_mo].[MobileOperatorID] ";
                }
                sqlCmdText += "WHERE [mom].[MOMessageID] = @MOMessageID;";

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

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

                MOMessageTable      momTable      = new MOMessageTable(query);
                MessageTable        mom_mTable    = (this.Depth > 0) ? new MessageTable(query) : null;
                ServiceTable        mom_m_sTable  = (this.Depth > 1) ? new ServiceTable(query) : null;
                CustomerTable       mom_m_cTable  = (this.Depth > 1) ? new CustomerTable(query) : null;
                MobileOperatorTable mom_m_moTable = (this.Depth > 1) ? new MobileOperatorTable(query) : null;


                Service        mom_m_sObject  = (this.Depth > 1) ? mom_m_sTable.CreateInstance() : null;
                Customer       mom_m_cObject  = (this.Depth > 1) ? mom_m_cTable.CreateInstance() : null;
                MobileOperator mom_m_moObject = (this.Depth > 1) ? mom_m_moTable.CreateInstance() : null;
                Message        mom_mObject    = (this.Depth > 0) ? mom_mTable.CreateInstance(mom_m_sObject, mom_m_cObject, mom_m_moObject) : null;
                MOMessage      momObject      = momTable.CreateInstance(mom_mObject);
                sqlReader.Close();

                return(momObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "loadinternal", "exception"), "MOMessage 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, "MOMessage", "Exception while loading MOMessage object from database. See inner exception for details.", ex);
            }
        }
Example #2
0
        public List <Message> LoadMany(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} " +
                             MessageTable.GetColumnNames("[m]") +
                             (this.Depth > 0 ? "," + ServiceTable.GetColumnNames("[m_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTable.GetColumnNames("[m_s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProductTable.GetColumnNames("[m_s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + MerchantTable.GetColumnNames("[m_s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTypeTable.GetColumnNames("[m_s_st]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserSessionTypeTable.GetColumnNames("[m_s_ust]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[m_s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[m_s_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceConfigurationTable.GetColumnNames("[m_s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[m_s_t]") : string.Empty) +
                             (this.Depth > 0 ? "," + CustomerTable.GetColumnNames("[m_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserTable.GetColumnNames("[m_c_u]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[m_c_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[m_c_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[m_c_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + MobileOperatorTable.GetColumnNames("[m_c_mo]") : string.Empty) +
                             (this.Depth > 0 ? "," + MobileOperatorTable.GetColumnNames("[m_mo]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[m_mo_c]") : string.Empty) +
                             " FROM [stats].[Message] AS [m] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Service] AS [m_s] ON [m].[ServiceID] = [m_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Application] AS [m_s_a] ON [m_s].[ApplicationID] = [m_s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Product] AS [m_s_p] ON [m_s].[ProductID] = [m_s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Merchant] AS [m_s_m] ON [m_s].[MerchantID] = [m_s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceType] AS [m_s_st] ON [m_s].[ServiceTypeID] = [m_s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserSessionType] AS [m_s_ust] ON [m_s].[UserSessionTypeID] = [m_s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Country] AS [m_s_c] ON [m_s].[FallbackCountryID] = [m_s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Language] AS [m_s_l] ON [m_s].[FallbackLanguageID] = [m_s_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [m_s_sc] ON [m_s].[ServiceConfigurationID] = [m_s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Template] AS [m_s_t] ON [m_s].[TemplateID] = [m_s_t].[TemplateID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Customer] AS [m_c] ON [m].[CustomerID] = [m_c].[CustomerID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[User] AS [m_c_u] ON [m_c].[UserID] = [m_c_u].[UserID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [m_c_s] ON [m_c].[ServiceID] = [m_c_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Country] AS [m_c_c] ON [m_c].[CountryID] = [m_c_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [m_c_l] ON [m_c].[LanguageID] = [m_c_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [m_c_mo] ON [m_c].[MobileOperatorID] = [m_c_mo].[MobileOperatorID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [m_mo] ON [m].[MobileOperatorID] = [m_mo].[MobileOperatorID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Country] AS [m_mo_c] ON [m_mo].[CountryID] = [m_mo_c].[CountryID] ";
                }


                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("m", "customloadmany", "notfound"), "Message list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(new List <Message>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                MessageTable              mTable       = new MessageTable(query);
                ServiceTable              m_sTable     = (this.Depth > 0) ? new ServiceTable(query) : null;
                ApplicationTable          m_s_aTable   = (this.Depth > 1) ? new ApplicationTable(query) : null;
                ProductTable              m_s_pTable   = (this.Depth > 1) ? new ProductTable(query) : null;
                MerchantTable             m_s_mTable   = (this.Depth > 1) ? new MerchantTable(query) : null;
                ServiceTypeTable          m_s_stTable  = (this.Depth > 1) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      m_s_ustTable = (this.Depth > 1) ? new UserSessionTypeTable(query) : null;
                CountryTable              m_s_cTable   = (this.Depth > 1) ? new CountryTable(query) : null;
                LanguageTable             m_s_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceConfigurationTable m_s_scTable  = (this.Depth > 1) ? new ServiceConfigurationTable(query) : null;
                TemplateTable             m_s_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;
                CustomerTable             m_cTable     = (this.Depth > 0) ? new CustomerTable(query) : null;
                UserTable           m_c_uTable         = (this.Depth > 1) ? new UserTable(query) : null;
                ServiceTable        m_c_sTable         = (this.Depth > 1) ? new ServiceTable(query) : null;
                CountryTable        m_c_cTable         = (this.Depth > 1) ? new CountryTable(query) : null;
                LanguageTable       m_c_lTable         = (this.Depth > 1) ? new LanguageTable(query) : null;
                MobileOperatorTable m_c_moTable        = (this.Depth > 1) ? new MobileOperatorTable(query) : null;
                MobileOperatorTable m_moTable          = (this.Depth > 0) ? new MobileOperatorTable(query) : null;
                CountryTable        m_mo_cTable        = (this.Depth > 1) ? new CountryTable(query) : null;

                List <Message> result = new List <Message>();
                do
                {
                    Application          m_s_aObject   = (this.Depth > 1) ? m_s_aTable.CreateInstance() : null;
                    Product              m_s_pObject   = (this.Depth > 1) ? m_s_pTable.CreateInstance() : null;
                    Merchant             m_s_mObject   = (this.Depth > 1) ? m_s_mTable.CreateInstance() : null;
                    ServiceType          m_s_stObject  = (this.Depth > 1) ? m_s_stTable.CreateInstance() : null;
                    UserSessionType      m_s_ustObject = (this.Depth > 1) ? m_s_ustTable.CreateInstance() : null;
                    Country              m_s_cObject   = (this.Depth > 1) ? m_s_cTable.CreateInstance() : null;
                    Language             m_s_lObject   = (this.Depth > 1) ? m_s_lTable.CreateInstance() : null;
                    ServiceConfiguration m_s_scObject  = (this.Depth > 1) ? m_s_scTable.CreateInstance() : null;
                    Template             m_s_tObject   = (this.Depth > 1) ? m_s_tTable.CreateInstance() : null;
                    Service              m_sObject     = (this.Depth > 0) ? m_sTable.CreateInstance(m_s_aObject, m_s_pObject, m_s_mObject, m_s_stObject, m_s_ustObject, m_s_cObject, m_s_lObject, m_s_scObject, m_s_tObject) : null;
                    User           m_c_uObject         = (this.Depth > 1) ? m_c_uTable.CreateInstance() : null;
                    Service        m_c_sObject         = (this.Depth > 1) ? m_c_sTable.CreateInstance() : null;
                    Country        m_c_cObject         = (this.Depth > 1) ? m_c_cTable.CreateInstance() : null;
                    Language       m_c_lObject         = (this.Depth > 1) ? m_c_lTable.CreateInstance() : null;
                    MobileOperator m_c_moObject        = (this.Depth > 1) ? m_c_moTable.CreateInstance() : null;
                    Customer       m_cObject           = (this.Depth > 0) ? m_cTable.CreateInstance(m_c_uObject, m_c_sObject, m_c_cObject, m_c_lObject, m_c_moObject) : null;
                    Country        m_mo_cObject        = (this.Depth > 1) ? m_mo_cTable.CreateInstance() : null;
                    MobileOperator m_moObject          = (this.Depth > 0) ? m_moTable.CreateInstance(m_mo_cObject) : null;
                    Message        mObject             = (this.Depth > -1) ? mTable.CreateInstance(m_sObject, m_cObject, m_moObject) : null;
                    result.Add(mObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("m", "customloadmany", "exception"), "Message list 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, "Message", "Exception while loading (custom/many) Message object from database. See inner exception for details.", ex);
            }
        }
Example #3
0
        public List <MOMessage> LoadMany(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} " +
                             MOMessageTable.GetColumnNames("[mom]") +
                             (this.Depth > 0 ? "," + MessageTable.GetColumnNames("[mom_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[mom_m_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + CustomerTable.GetColumnNames("[mom_m_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + MobileOperatorTable.GetColumnNames("[mom_m_mo]") : string.Empty) +
                             " FROM [stats].[MOMessage] AS [mom] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [stats].[Message] AS [mom_m] ON [mom].[MessageID] = [mom_m].[MessageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Service] AS [mom_m_s] ON [mom_m].[ServiceID] = [mom_m_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Customer] AS [mom_m_c] ON [mom_m].[CustomerID] = [mom_m_c].[CustomerID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [mom_m_mo] ON [mom_m].[MobileOperatorID] = [mom_m_mo].[MobileOperatorID] ";
                }


                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("mom", "customloadmany", "notfound"), "MOMessage list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(new List <MOMessage>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                MOMessageTable      momTable      = new MOMessageTable(query);
                MessageTable        mom_mTable    = (this.Depth > 0) ? new MessageTable(query) : null;
                ServiceTable        mom_m_sTable  = (this.Depth > 1) ? new ServiceTable(query) : null;
                CustomerTable       mom_m_cTable  = (this.Depth > 1) ? new CustomerTable(query) : null;
                MobileOperatorTable mom_m_moTable = (this.Depth > 1) ? new MobileOperatorTable(query) : null;

                List <MOMessage> result = new List <MOMessage>();
                do
                {
                    Service        mom_m_sObject  = (this.Depth > 1) ? mom_m_sTable.CreateInstance() : null;
                    Customer       mom_m_cObject  = (this.Depth > 1) ? mom_m_cTable.CreateInstance() : null;
                    MobileOperator mom_m_moObject = (this.Depth > 1) ? mom_m_moTable.CreateInstance() : null;
                    Message        mom_mObject    = (this.Depth > 0) ? mom_mTable.CreateInstance(mom_m_sObject, mom_m_cObject, mom_m_moObject) : null;
                    MOMessage      momObject      = (this.Depth > -1) ? momTable.CreateInstance(mom_mObject) : null;
                    result.Add(momObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "customloadmany", "exception"), "MOMessage list 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, "MOMessage", "Exception while loading (custom/many) MOMessage object from database. See inner exception for details.", ex);
            }
        }
Example #4
0
        protected override Message 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 " +
                             MessageTable.GetColumnNames("[m]") +
                             (this.Depth > 0 ? "," + ServiceTable.GetColumnNames("[m_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTable.GetColumnNames("[m_s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProductTable.GetColumnNames("[m_s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + MerchantTable.GetColumnNames("[m_s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTypeTable.GetColumnNames("[m_s_st]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserSessionTypeTable.GetColumnNames("[m_s_ust]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[m_s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[m_s_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceConfigurationTable.GetColumnNames("[m_s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[m_s_t]") : string.Empty) +
                             (this.Depth > 0 ? "," + CustomerTable.GetColumnNames("[m_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserTable.GetColumnNames("[m_c_u]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[m_c_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[m_c_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[m_c_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + MobileOperatorTable.GetColumnNames("[m_c_mo]") : string.Empty) +
                             (this.Depth > 0 ? "," + MobileOperatorTable.GetColumnNames("[m_mo]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[m_mo_c]") : string.Empty) +
                             " FROM [stats].[Message] AS [m] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Service] AS [m_s] ON [m].[ServiceID] = [m_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Application] AS [m_s_a] ON [m_s].[ApplicationID] = [m_s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Product] AS [m_s_p] ON [m_s].[ProductID] = [m_s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Merchant] AS [m_s_m] ON [m_s].[MerchantID] = [m_s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceType] AS [m_s_st] ON [m_s].[ServiceTypeID] = [m_s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserSessionType] AS [m_s_ust] ON [m_s].[UserSessionTypeID] = [m_s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Country] AS [m_s_c] ON [m_s].[FallbackCountryID] = [m_s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Language] AS [m_s_l] ON [m_s].[FallbackLanguageID] = [m_s_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [m_s_sc] ON [m_s].[ServiceConfigurationID] = [m_s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Template] AS [m_s_t] ON [m_s].[TemplateID] = [m_s_t].[TemplateID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Customer] AS [m_c] ON [m].[CustomerID] = [m_c].[CustomerID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[User] AS [m_c_u] ON [m_c].[UserID] = [m_c_u].[UserID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [m_c_s] ON [m_c].[ServiceID] = [m_c_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Country] AS [m_c_c] ON [m_c].[CountryID] = [m_c_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [m_c_l] ON [m_c].[LanguageID] = [m_c_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [m_c_mo] ON [m_c].[MobileOperatorID] = [m_c_mo].[MobileOperatorID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [m_mo] ON [m].[MobileOperatorID] = [m_mo].[MobileOperatorID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Country] AS [m_mo_c] ON [m_mo].[CountryID] = [m_mo_c].[CountryID] ";
                }
                sqlCmdText += "WHERE [m].[MessageID] = @MessageID;";

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

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

                MessageTable              mTable       = new MessageTable(query);
                ServiceTable              m_sTable     = (this.Depth > 0) ? new ServiceTable(query) : null;
                ApplicationTable          m_s_aTable   = (this.Depth > 1) ? new ApplicationTable(query) : null;
                ProductTable              m_s_pTable   = (this.Depth > 1) ? new ProductTable(query) : null;
                MerchantTable             m_s_mTable   = (this.Depth > 1) ? new MerchantTable(query) : null;
                ServiceTypeTable          m_s_stTable  = (this.Depth > 1) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      m_s_ustTable = (this.Depth > 1) ? new UserSessionTypeTable(query) : null;
                CountryTable              m_s_cTable   = (this.Depth > 1) ? new CountryTable(query) : null;
                LanguageTable             m_s_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceConfigurationTable m_s_scTable  = (this.Depth > 1) ? new ServiceConfigurationTable(query) : null;
                TemplateTable             m_s_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;
                CustomerTable             m_cTable     = (this.Depth > 0) ? new CustomerTable(query) : null;
                UserTable           m_c_uTable         = (this.Depth > 1) ? new UserTable(query) : null;
                ServiceTable        m_c_sTable         = (this.Depth > 1) ? new ServiceTable(query) : null;
                CountryTable        m_c_cTable         = (this.Depth > 1) ? new CountryTable(query) : null;
                LanguageTable       m_c_lTable         = (this.Depth > 1) ? new LanguageTable(query) : null;
                MobileOperatorTable m_c_moTable        = (this.Depth > 1) ? new MobileOperatorTable(query) : null;
                MobileOperatorTable m_moTable          = (this.Depth > 0) ? new MobileOperatorTable(query) : null;
                CountryTable        m_mo_cTable        = (this.Depth > 1) ? new CountryTable(query) : null;


                Application          m_s_aObject   = (this.Depth > 1) ? m_s_aTable.CreateInstance() : null;
                Product              m_s_pObject   = (this.Depth > 1) ? m_s_pTable.CreateInstance() : null;
                Merchant             m_s_mObject   = (this.Depth > 1) ? m_s_mTable.CreateInstance() : null;
                ServiceType          m_s_stObject  = (this.Depth > 1) ? m_s_stTable.CreateInstance() : null;
                UserSessionType      m_s_ustObject = (this.Depth > 1) ? m_s_ustTable.CreateInstance() : null;
                Country              m_s_cObject   = (this.Depth > 1) ? m_s_cTable.CreateInstance() : null;
                Language             m_s_lObject   = (this.Depth > 1) ? m_s_lTable.CreateInstance() : null;
                ServiceConfiguration m_s_scObject  = (this.Depth > 1) ? m_s_scTable.CreateInstance() : null;
                Template             m_s_tObject   = (this.Depth > 1) ? m_s_tTable.CreateInstance() : null;
                Service              m_sObject     = (this.Depth > 0) ? m_sTable.CreateInstance(m_s_aObject, m_s_pObject, m_s_mObject, m_s_stObject, m_s_ustObject, m_s_cObject, m_s_lObject, m_s_scObject, m_s_tObject) : null;
                User           m_c_uObject         = (this.Depth > 1) ? m_c_uTable.CreateInstance() : null;
                Service        m_c_sObject         = (this.Depth > 1) ? m_c_sTable.CreateInstance() : null;
                Country        m_c_cObject         = (this.Depth > 1) ? m_c_cTable.CreateInstance() : null;
                Language       m_c_lObject         = (this.Depth > 1) ? m_c_lTable.CreateInstance() : null;
                MobileOperator m_c_moObject        = (this.Depth > 1) ? m_c_moTable.CreateInstance() : null;
                Customer       m_cObject           = (this.Depth > 0) ? m_cTable.CreateInstance(m_c_uObject, m_c_sObject, m_c_cObject, m_c_lObject, m_c_moObject) : null;
                Country        m_mo_cObject        = (this.Depth > 1) ? m_mo_cTable.CreateInstance() : null;
                MobileOperator m_moObject          = (this.Depth > 0) ? m_moTable.CreateInstance(m_mo_cObject) : null;
                Message        mObject             = mTable.CreateInstance(m_sObject, m_cObject, m_moObject);
                sqlReader.Close();

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