protected override RuntimeType 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 " +
                             RuntimeTypeTable.GetColumnNames("[rt]") +
                             " FROM [core].[RuntimeType] AS [rt] ";
                sqlCmdText += "WHERE [rt].[RuntimeTypeID] = @RuntimeTypeID;";

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

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

                RuntimeTypeTable rtTable = new RuntimeTypeTable(query);


                RuntimeType rtObject = rtTable.CreateInstance();
                sqlReader.Close();

                return(rtObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rt", "loadinternal", "exception"), "RuntimeType 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, "RuntimeType", "Exception while loading RuntimeType object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 2
0
        public List <Service> 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} " +
                             ServiceTable.GetColumnNames("[s]") +
                             (this.Depth > 0 ? "," + ApplicationTable.GetColumnNames("[s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_a_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTypeTable.GetColumnNames("[s_a_at]") : string.Empty) +
                             (this.Depth > 1 ? "," + RuntimeTypeTable.GetColumnNames("[s_a_rt]") : string.Empty) +
                             (this.Depth > 0 ? "," + ProductTable.GetColumnNames("[s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_p_i]") : string.Empty) +
                             (this.Depth > 0 ? "," + MerchantTable.GetColumnNames("[s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_m_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[s_m_t]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceTypeTable.GetColumnNames("[s_st]") : string.Empty) +
                             (this.Depth > 0 ? "," + UserSessionTypeTable.GetColumnNames("[s_ust]") : string.Empty) +
                             (this.Depth > 0 ? "," + CountryTable.GetColumnNames("[s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[s_c_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + LanguageTable.GetColumnNames("[s_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceConfigurationTable.GetColumnNames("[s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + PaymentConfigurationTable.GetColumnNames("[s_sc_pc]") : string.Empty) +
                             (this.Depth > 0 ? "," + TemplateTable.GetColumnNames("[s_t]") : string.Empty) +
                             " FROM [core].[Service] AS [s] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Application] AS [s_a] ON [s].[ApplicationID] = [s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_a_i] ON [s_a].[InstanceID] = [s_a_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ApplicationType] AS [s_a_at] ON [s_a].[ApplicationTypeID] = [s_a_at].[ApplicationTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[RuntimeType] AS [s_a_rt] ON [s_a].[RuntimeTypeID] = [s_a_rt].[RuntimeTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Product] AS [s_p] ON [s].[ProductID] = [s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_p_i] ON [s_p].[InstanceID] = [s_p_i].[InstanceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Merchant] AS [s_m] ON [s].[MerchantID] = [s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_m_i] ON [s_m].[InstanceID] = [s_m_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Template] AS [s_m_t] ON [s_m].[TemplateID] = [s_m_t].[TemplateID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceType] AS [s_st] ON [s].[ServiceTypeID] = [s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserSessionType] AS [s_ust] ON [s].[UserSessionTypeID] = [s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Country] AS [s_c] ON [s].[FallbackCountryID] = [s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [s_c_l] ON [s_c].[LanguageID] = [s_c_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Language] AS [s_l] ON [s].[FallbackLanguageID] = [s_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [s_sc] ON [s].[ServiceConfigurationID] = [s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentConfiguration] AS [s_sc_pc] ON [s_sc].[PaymentConfigurationID] = [s_sc_pc].[PaymentConfigurationID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Template] AS [s_t] ON [s].[TemplateID] = [s_t].[TemplateID] ";
                }


                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("s", "customloadmany", "notfound"), "Service 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 <Service>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ServiceTable              sTable       = new ServiceTable(query);
                ApplicationTable          s_aTable     = (this.Depth > 0) ? new ApplicationTable(query) : null;
                InstanceTable             s_a_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                ApplicationTypeTable      s_a_atTable  = (this.Depth > 1) ? new ApplicationTypeTable(query) : null;
                RuntimeTypeTable          s_a_rtTable  = (this.Depth > 1) ? new RuntimeTypeTable(query) : null;
                ProductTable              s_pTable     = (this.Depth > 0) ? new ProductTable(query) : null;
                InstanceTable             s_p_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                MerchantTable             s_mTable     = (this.Depth > 0) ? new MerchantTable(query) : null;
                InstanceTable             s_m_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                TemplateTable             s_m_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;
                ServiceTypeTable          s_stTable    = (this.Depth > 0) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      s_ustTable   = (this.Depth > 0) ? new UserSessionTypeTable(query) : null;
                CountryTable              s_cTable     = (this.Depth > 0) ? new CountryTable(query) : null;
                LanguageTable             s_c_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                LanguageTable             s_lTable     = (this.Depth > 0) ? new LanguageTable(query) : null;
                ServiceConfigurationTable s_scTable    = (this.Depth > 0) ? new ServiceConfigurationTable(query) : null;
                PaymentConfigurationTable s_sc_pcTable = (this.Depth > 1) ? new PaymentConfigurationTable(query) : null;
                TemplateTable             s_tTable     = (this.Depth > 0) ? new TemplateTable(query) : null;

                List <Service> result = new List <Service>();
                do
                {
                    Instance             s_a_iObject   = (this.Depth > 1) ? s_a_iTable.CreateInstance() : null;
                    ApplicationType      s_a_atObject  = (this.Depth > 1) ? s_a_atTable.CreateInstance() : null;
                    RuntimeType          s_a_rtObject  = (this.Depth > 1) ? s_a_rtTable.CreateInstance() : null;
                    Application          s_aObject     = (this.Depth > 0) ? s_aTable.CreateInstance(s_a_iObject, s_a_atObject, s_a_rtObject) : null;
                    Instance             s_p_iObject   = (this.Depth > 1) ? s_p_iTable.CreateInstance() : null;
                    Product              s_pObject     = (this.Depth > 0) ? s_pTable.CreateInstance(s_p_iObject) : null;
                    Instance             s_m_iObject   = (this.Depth > 1) ? s_m_iTable.CreateInstance() : null;
                    Template             s_m_tObject   = (this.Depth > 1) ? s_m_tTable.CreateInstance() : null;
                    Merchant             s_mObject     = (this.Depth > 0) ? s_mTable.CreateInstance(s_m_iObject, s_m_tObject) : null;
                    ServiceType          s_stObject    = (this.Depth > 0) ? s_stTable.CreateInstance() : null;
                    UserSessionType      s_ustObject   = (this.Depth > 0) ? s_ustTable.CreateInstance() : null;
                    Language             s_c_lObject   = (this.Depth > 1) ? s_c_lTable.CreateInstance() : null;
                    Country              s_cObject     = (this.Depth > 0) ? s_cTable.CreateInstance(s_c_lObject) : null;
                    Language             s_lObject     = (this.Depth > 0) ? s_lTable.CreateInstance() : null;
                    PaymentConfiguration s_sc_pcObject = (this.Depth > 1) ? s_sc_pcTable.CreateInstance() : null;
                    ServiceConfiguration s_scObject    = (this.Depth > 0) ? s_scTable.CreateInstance(s_sc_pcObject) : null;
                    Template             s_tObject     = (this.Depth > 0) ? s_tTable.CreateInstance() : null;
                    Service              sObject       = (this.Depth > -1) ? sTable.CreateInstance(s_aObject, s_pObject, s_mObject, s_stObject, s_ustObject, s_cObject, s_lObject, s_scObject, s_tObject) : null;
                    result.Add(sObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("s", "customloadmany", "exception"), "Service 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, "Service", "Exception while loading (custom/many) Service object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 3
0
        protected override Service 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 " +
                             ServiceTable.GetColumnNames("[s]") +
                             (this.Depth > 0 ? "," + ApplicationTable.GetColumnNames("[s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_a_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTypeTable.GetColumnNames("[s_a_at]") : string.Empty) +
                             (this.Depth > 1 ? "," + RuntimeTypeTable.GetColumnNames("[s_a_rt]") : string.Empty) +
                             (this.Depth > 0 ? "," + ProductTable.GetColumnNames("[s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_p_i]") : string.Empty) +
                             (this.Depth > 0 ? "," + MerchantTable.GetColumnNames("[s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_m_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[s_m_t]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceTypeTable.GetColumnNames("[s_st]") : string.Empty) +
                             (this.Depth > 0 ? "," + UserSessionTypeTable.GetColumnNames("[s_ust]") : string.Empty) +
                             (this.Depth > 0 ? "," + CountryTable.GetColumnNames("[s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[s_c_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + LanguageTable.GetColumnNames("[s_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceConfigurationTable.GetColumnNames("[s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + PaymentConfigurationTable.GetColumnNames("[s_sc_pc]") : string.Empty) +
                             (this.Depth > 0 ? "," + TemplateTable.GetColumnNames("[s_t]") : string.Empty) +
                             " FROM [core].[Service] AS [s] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Application] AS [s_a] ON [s].[ApplicationID] = [s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_a_i] ON [s_a].[InstanceID] = [s_a_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ApplicationType] AS [s_a_at] ON [s_a].[ApplicationTypeID] = [s_a_at].[ApplicationTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[RuntimeType] AS [s_a_rt] ON [s_a].[RuntimeTypeID] = [s_a_rt].[RuntimeTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Product] AS [s_p] ON [s].[ProductID] = [s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_p_i] ON [s_p].[InstanceID] = [s_p_i].[InstanceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Merchant] AS [s_m] ON [s].[MerchantID] = [s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_m_i] ON [s_m].[InstanceID] = [s_m_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Template] AS [s_m_t] ON [s_m].[TemplateID] = [s_m_t].[TemplateID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceType] AS [s_st] ON [s].[ServiceTypeID] = [s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserSessionType] AS [s_ust] ON [s].[UserSessionTypeID] = [s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Country] AS [s_c] ON [s].[FallbackCountryID] = [s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [s_c_l] ON [s_c].[LanguageID] = [s_c_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Language] AS [s_l] ON [s].[FallbackLanguageID] = [s_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [s_sc] ON [s].[ServiceConfigurationID] = [s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentConfiguration] AS [s_sc_pc] ON [s_sc].[PaymentConfigurationID] = [s_sc_pc].[PaymentConfigurationID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Template] AS [s_t] ON [s].[TemplateID] = [s_t].[TemplateID] ";
                }
                sqlCmdText += "WHERE [s].[ServiceID] = @ServiceID;";

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

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

                ServiceTable              sTable       = new ServiceTable(query);
                ApplicationTable          s_aTable     = (this.Depth > 0) ? new ApplicationTable(query) : null;
                InstanceTable             s_a_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                ApplicationTypeTable      s_a_atTable  = (this.Depth > 1) ? new ApplicationTypeTable(query) : null;
                RuntimeTypeTable          s_a_rtTable  = (this.Depth > 1) ? new RuntimeTypeTable(query) : null;
                ProductTable              s_pTable     = (this.Depth > 0) ? new ProductTable(query) : null;
                InstanceTable             s_p_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                MerchantTable             s_mTable     = (this.Depth > 0) ? new MerchantTable(query) : null;
                InstanceTable             s_m_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                TemplateTable             s_m_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;
                ServiceTypeTable          s_stTable    = (this.Depth > 0) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      s_ustTable   = (this.Depth > 0) ? new UserSessionTypeTable(query) : null;
                CountryTable              s_cTable     = (this.Depth > 0) ? new CountryTable(query) : null;
                LanguageTable             s_c_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                LanguageTable             s_lTable     = (this.Depth > 0) ? new LanguageTable(query) : null;
                ServiceConfigurationTable s_scTable    = (this.Depth > 0) ? new ServiceConfigurationTable(query) : null;
                PaymentConfigurationTable s_sc_pcTable = (this.Depth > 1) ? new PaymentConfigurationTable(query) : null;
                TemplateTable             s_tTable     = (this.Depth > 0) ? new TemplateTable(query) : null;


                Instance             s_a_iObject   = (this.Depth > 1) ? s_a_iTable.CreateInstance() : null;
                ApplicationType      s_a_atObject  = (this.Depth > 1) ? s_a_atTable.CreateInstance() : null;
                RuntimeType          s_a_rtObject  = (this.Depth > 1) ? s_a_rtTable.CreateInstance() : null;
                Application          s_aObject     = (this.Depth > 0) ? s_aTable.CreateInstance(s_a_iObject, s_a_atObject, s_a_rtObject) : null;
                Instance             s_p_iObject   = (this.Depth > 1) ? s_p_iTable.CreateInstance() : null;
                Product              s_pObject     = (this.Depth > 0) ? s_pTable.CreateInstance(s_p_iObject) : null;
                Instance             s_m_iObject   = (this.Depth > 1) ? s_m_iTable.CreateInstance() : null;
                Template             s_m_tObject   = (this.Depth > 1) ? s_m_tTable.CreateInstance() : null;
                Merchant             s_mObject     = (this.Depth > 0) ? s_mTable.CreateInstance(s_m_iObject, s_m_tObject) : null;
                ServiceType          s_stObject    = (this.Depth > 0) ? s_stTable.CreateInstance() : null;
                UserSessionType      s_ustObject   = (this.Depth > 0) ? s_ustTable.CreateInstance() : null;
                Language             s_c_lObject   = (this.Depth > 1) ? s_c_lTable.CreateInstance() : null;
                Country              s_cObject     = (this.Depth > 0) ? s_cTable.CreateInstance(s_c_lObject) : null;
                Language             s_lObject     = (this.Depth > 0) ? s_lTable.CreateInstance() : null;
                PaymentConfiguration s_sc_pcObject = (this.Depth > 1) ? s_sc_pcTable.CreateInstance() : null;
                ServiceConfiguration s_scObject    = (this.Depth > 0) ? s_scTable.CreateInstance(s_sc_pcObject) : null;
                Template             s_tObject     = (this.Depth > 0) ? s_tTable.CreateInstance() : null;
                Service              sObject       = sTable.CreateInstance(s_aObject, s_pObject, s_mObject, s_stObject, s_ustObject, s_cObject, s_lObject, s_scObject, s_tObject);
                sqlReader.Close();

                return(sObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("s", "loadinternal", "exception"), "Service 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, "Service", "Exception while loading Service object from database. See inner exception for details.", ex);
            }
        }
        public RuntimeType 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} " +
                             RuntimeTypeTable.GetColumnNames("[rt]") +
                             " FROM [core].[RuntimeType] AS [rt] ";


                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("rt", "customload", "notfound"), "RuntimeType 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);

                RuntimeTypeTable rtTable = new RuntimeTypeTable(query);


                RuntimeType rtObject = rtTable.CreateInstance();
                sqlReader.Close();

                return(rtObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rt", "customload", "exception"), "RuntimeType 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, "RuntimeType", "Exception while loading (custom/single) RuntimeType object from database. See inner exception for details.", ex);
            }
        }
        protected override Application 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 " +
                             ApplicationTable.GetColumnNames("[a]") +
                             (this.Depth > 0 ? "," + InstanceTable.GetColumnNames("[a_i]") : string.Empty) +
                             (this.Depth > 0 ? "," + ApplicationTypeTable.GetColumnNames("[a_at]") : string.Empty) +
                             (this.Depth > 0 ? "," + RuntimeTypeTable.GetColumnNames("[a_rt]") : string.Empty) +
                             " FROM [core].[Application] AS [a] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [a_i] ON [a].[InstanceID] = [a_i].[InstanceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ApplicationType] AS [a_at] ON [a].[ApplicationTypeID] = [a_at].[ApplicationTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[RuntimeType] AS [a_rt] ON [a].[RuntimeTypeID] = [a_rt].[RuntimeTypeID] ";
                }
                sqlCmdText += "WHERE [a].[ApplicationID] = @ApplicationID;";

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

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

                ApplicationTable     aTable    = new ApplicationTable(query);
                InstanceTable        a_iTable  = (this.Depth > 0) ? new InstanceTable(query) : null;
                ApplicationTypeTable a_atTable = (this.Depth > 0) ? new ApplicationTypeTable(query) : null;
                RuntimeTypeTable     a_rtTable = (this.Depth > 0) ? new RuntimeTypeTable(query) : null;


                Instance        a_iObject  = (this.Depth > 0) ? a_iTable.CreateInstance() : null;
                ApplicationType a_atObject = (this.Depth > 0) ? a_atTable.CreateInstance() : null;
                RuntimeType     a_rtObject = (this.Depth > 0) ? a_rtTable.CreateInstance() : null;
                Application     aObject    = aTable.CreateInstance(a_iObject, a_atObject, a_rtObject);
                sqlReader.Close();

                return(aObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("a", "loadinternal", "exception"), "Application 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, "Application", "Exception while loading Application object from database. See inner exception for details.", ex);
            }
        }
        public List <Application> 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} " +
                             ApplicationTable.GetColumnNames("[a]") +
                             (this.Depth > 0 ? "," + InstanceTable.GetColumnNames("[a_i]") : string.Empty) +
                             (this.Depth > 0 ? "," + ApplicationTypeTable.GetColumnNames("[a_at]") : string.Empty) +
                             (this.Depth > 0 ? "," + RuntimeTypeTable.GetColumnNames("[a_rt]") : string.Empty) +
                             " FROM [core].[Application] AS [a] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [a_i] ON [a].[InstanceID] = [a_i].[InstanceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ApplicationType] AS [a_at] ON [a].[ApplicationTypeID] = [a_at].[ApplicationTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[RuntimeType] AS [a_rt] ON [a].[RuntimeTypeID] = [a_rt].[RuntimeTypeID] ";
                }


                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("a", "customloadmany", "notfound"), "Application 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 <Application>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ApplicationTable     aTable    = new ApplicationTable(query);
                InstanceTable        a_iTable  = (this.Depth > 0) ? new InstanceTable(query) : null;
                ApplicationTypeTable a_atTable = (this.Depth > 0) ? new ApplicationTypeTable(query) : null;
                RuntimeTypeTable     a_rtTable = (this.Depth > 0) ? new RuntimeTypeTable(query) : null;

                List <Application> result = new List <Application>();
                do
                {
                    Instance        a_iObject  = (this.Depth > 0) ? a_iTable.CreateInstance() : null;
                    ApplicationType a_atObject = (this.Depth > 0) ? a_atTable.CreateInstance() : null;
                    RuntimeType     a_rtObject = (this.Depth > 0) ? a_rtTable.CreateInstance() : null;
                    Application     aObject    = (this.Depth > -1) ? aTable.CreateInstance(a_iObject, a_atObject, a_rtObject) : null;
                    result.Add(aObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("a", "customloadmany", "exception"), "Application 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, "Application", "Exception while loading (custom/many) Application object from database. See inner exception for details.", ex);
            }
        }
        public Localization 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} " +
                             LocalizationTable.GetColumnNames("[l]") +
                             (this.Depth > 0 ? "," + ApplicationTable.GetColumnNames("[l_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[l_a_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTypeTable.GetColumnNames("[l_a_at]") : string.Empty) +
                             (this.Depth > 1 ? "," + RuntimeTypeTable.GetColumnNames("[l_a_rt]") : string.Empty) +
                             (this.Depth > 0 ? "," + ProductTable.GetColumnNames("[l_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[l_p_i]") : string.Empty) +
                             (this.Depth > 0 ? "," + TranslationTable.GetColumnNames("[l_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTypeTable.GetColumnNames("[l_t_tt]") : string.Empty) +
                             " FROM [core].[Localization] AS [l] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Application] AS [l_a] ON [l].[ApplicationID] = [l_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [l_a_i] ON [l_a].[InstanceID] = [l_a_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ApplicationType] AS [l_a_at] ON [l_a].[ApplicationTypeID] = [l_a_at].[ApplicationTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[RuntimeType] AS [l_a_rt] ON [l_a].[RuntimeTypeID] = [l_a_rt].[RuntimeTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Product] AS [l_p] ON [l].[ProductID] = [l_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Instance] AS [l_p_i] ON [l_p].[InstanceID] = [l_p_i].[InstanceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Translation] AS [l_t] ON [l].[TranslationID] = [l_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationType] AS [l_t_tt] ON [l_t].[TranslationTypeID] = [l_t_tt].[TranslationTypeID] ";
                }


                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("l", "customload", "notfound"), "Localization 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);

                LocalizationTable    lTable      = new LocalizationTable(query);
                ApplicationTable     l_aTable    = (this.Depth > 0) ? new ApplicationTable(query) : null;
                InstanceTable        l_a_iTable  = (this.Depth > 1) ? new InstanceTable(query) : null;
                ApplicationTypeTable l_a_atTable = (this.Depth > 1) ? new ApplicationTypeTable(query) : null;
                RuntimeTypeTable     l_a_rtTable = (this.Depth > 1) ? new RuntimeTypeTable(query) : null;
                ProductTable         l_pTable    = (this.Depth > 0) ? new ProductTable(query) : null;
                InstanceTable        l_p_iTable  = (this.Depth > 1) ? new InstanceTable(query) : null;
                TranslationTable     l_tTable    = (this.Depth > 0) ? new TranslationTable(query) : null;
                TranslationTypeTable l_t_ttTable = (this.Depth > 1) ? new TranslationTypeTable(query) : null;


                Instance        l_a_iObject  = (this.Depth > 1) ? l_a_iTable.CreateInstance() : null;
                ApplicationType l_a_atObject = (this.Depth > 1) ? l_a_atTable.CreateInstance() : null;
                RuntimeType     l_a_rtObject = (this.Depth > 1) ? l_a_rtTable.CreateInstance() : null;
                Application     l_aObject    = (this.Depth > 0) ? l_aTable.CreateInstance(l_a_iObject, l_a_atObject, l_a_rtObject) : null;
                Instance        l_p_iObject  = (this.Depth > 1) ? l_p_iTable.CreateInstance() : null;
                Product         l_pObject    = (this.Depth > 0) ? l_pTable.CreateInstance(l_p_iObject) : null;
                TranslationType l_t_ttObject = (this.Depth > 1) ? l_t_ttTable.CreateInstance() : null;
                Translation     l_tObject    = (this.Depth > 0) ? l_tTable.CreateInstance(l_t_ttObject) : null;
                Localization    lObject      = lTable.CreateInstance(l_aObject, l_pObject, l_tObject);
                sqlReader.Close();

                return(lObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("l", "customload", "exception"), "Localization 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, "Localization", "Exception while loading (custom/single) Localization object from database. See inner exception for details.", ex);
            }
        }