protected override ProfileCategory 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 " +
                             ProfileCategoryTable.GetColumnNames("[pc]") +
                             " FROM [web].[ProfileCategory] AS [pc] ";
                sqlCmdText += "WHERE [pc].[ProfileCategoryID] = @ProfileCategoryID;";

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

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

                ProfileCategoryTable pcTable = new ProfileCategoryTable(query);


                ProfileCategory pcObject = pcTable.CreateInstance();
                sqlReader.Close();

                return(pcObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "loadinternal", "exception"), "ProfileCategory 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, "ProfileCategory", "Exception while loading ProfileCategory object from database. See inner exception for details.", ex);
            }
        }
        public ProfileCategory 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} " +
                             ProfileCategoryTable.GetColumnNames("[pc]") +
                             " FROM [web].[ProfileCategory] AS [pc] ";


                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("pc", "customload", "notfound"), "ProfileCategory 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);

                ProfileCategoryTable pcTable = new ProfileCategoryTable(query);


                ProfileCategory pcObject = pcTable.CreateInstance();
                sqlReader.Close();

                return(pcObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "customload", "exception"), "ProfileCategory 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, "ProfileCategory", "Exception while loading (custom/single) ProfileCategory object from database. See inner exception for details.", ex);
            }
        }
Example #3
0
        public ServiceProfileGroupMap 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} " +
                             ServiceProfileGroupMapTable.GetColumnNames("[spgm]") +
                             (this.Depth > 0 ? "," + ProfileGroupTable.GetColumnNames("[spgm_pg]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProfileCategoryTable.GetColumnNames("[spgm_pg_pc]") : string.Empty) +
                             " FROM [web].[ServiceProfileGroupMap] AS [spgm] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileGroup] AS [spgm_pg] ON [spgm].[ProfileGroupID] = [spgm_pg].[ProfileGroupID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileCategory] AS [spgm_pg_pc] ON [spgm_pg].[ProfileCategoryID] = [spgm_pg_pc].[ProfileCategoryID] ";
                }


                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("spgm", "customload", "notfound"), "ServiceProfileGroupMap 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);

                ServiceProfileGroupMapTable spgmTable       = new ServiceProfileGroupMapTable(query);
                ProfileGroupTable           spgm_pgTable    = (this.Depth > 0) ? new ProfileGroupTable(query) : null;
                ProfileCategoryTable        spgm_pg_pcTable = (this.Depth > 1) ? new ProfileCategoryTable(query) : null;


                ProfileCategory        spgm_pg_pcObject = (this.Depth > 1) ? spgm_pg_pcTable.CreateInstance() : null;
                ProfileGroup           spgm_pgObject    = (this.Depth > 0) ? spgm_pgTable.CreateInstance(spgm_pg_pcObject) : null;
                ServiceProfileGroupMap spgmObject       = spgmTable.CreateInstance(spgm_pgObject);
                sqlReader.Close();

                return(spgmObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("spgm", "customload", "exception"), "ServiceProfileGroupMap 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, "ServiceProfileGroupMap", "Exception while loading (custom/single) ServiceProfileGroupMap object from database. See inner exception for details.", ex);
            }
        }
Example #4
0
        public List <ProfileGroup> 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} " +
                             ProfileGroupTable.GetColumnNames("[pg]") +
                             (this.Depth > 0 ? "," + ProfileCategoryTable.GetColumnNames("[pg_pc]") : string.Empty) +
                             (this.Depth > 0 ? "," + InstanceTable.GetColumnNames("[pg_i]") : string.Empty) +
                             " FROM [web].[ProfileGroup] AS [pg] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileCategory] AS [pg_pc] ON [pg].[ProfileCategoryID] = [pg_pc].[ProfileCategoryID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [pg_i] ON [pg].[InstanceID] = [pg_i].[InstanceID] ";
                }


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

                SqlQuery query = new SqlQuery(sqlReader);

                ProfileGroupTable    pgTable    = new ProfileGroupTable(query);
                ProfileCategoryTable pg_pcTable = (this.Depth > 0) ? new ProfileCategoryTable(query) : null;
                InstanceTable        pg_iTable  = (this.Depth > 0) ? new InstanceTable(query) : null;

                List <ProfileGroup> result = new List <ProfileGroup>();
                do
                {
                    ProfileCategory pg_pcObject = (this.Depth > 0) ? pg_pcTable.CreateInstance() : null;
                    Instance        pg_iObject  = (this.Depth > 0) ? pg_iTable.CreateInstance() : null;
                    ProfileGroup    pgObject    = (this.Depth > -1) ? pgTable.CreateInstance(pg_pcObject, pg_iObject) : null;
                    result.Add(pgObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pg", "customloadmany", "exception"), "ProfileGroup 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, "ProfileGroup", "Exception while loading (custom/many) ProfileGroup object from database. See inner exception for details.", ex);
            }
        }
Example #5
0
        protected override ServiceProfileGroupMap 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 " +
                             ServiceProfileGroupMapTable.GetColumnNames("[spgm]") +
                             (this.Depth > 0 ? "," + ProfileGroupTable.GetColumnNames("[spgm_pg]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProfileCategoryTable.GetColumnNames("[spgm_pg_pc]") : string.Empty) +
                             " FROM [web].[ServiceProfileGroupMap] AS [spgm] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileGroup] AS [spgm_pg] ON [spgm].[ProfileGroupID] = [spgm_pg].[ProfileGroupID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileCategory] AS [spgm_pg_pc] ON [spgm_pg].[ProfileCategoryID] = [spgm_pg_pc].[ProfileCategoryID] ";
                }
                sqlCmdText += "WHERE [spgm].[ServiceProfileGroupMapID] = @ServiceProfileGroupMapID;";

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

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

                ServiceProfileGroupMapTable spgmTable       = new ServiceProfileGroupMapTable(query);
                ProfileGroupTable           spgm_pgTable    = (this.Depth > 0) ? new ProfileGroupTable(query) : null;
                ProfileCategoryTable        spgm_pg_pcTable = (this.Depth > 1) ? new ProfileCategoryTable(query) : null;


                ProfileCategory        spgm_pg_pcObject = (this.Depth > 1) ? spgm_pg_pcTable.CreateInstance() : null;
                ProfileGroup           spgm_pgObject    = (this.Depth > 0) ? spgm_pgTable.CreateInstance(spgm_pg_pcObject) : null;
                ServiceProfileGroupMap spgmObject       = spgmTable.CreateInstance(spgm_pgObject);
                sqlReader.Close();

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