protected override ProfileThumbnail 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 " +
                             ProfileThumbnailTable.GetColumnNames("[pt]") +
                             (this.Depth > 0 ? "," + ProfileTable.GetColumnNames("[pt_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProfileGroupTable.GetColumnNames("[pt_p_pg]") : string.Empty) +
                             " FROM [web].[ProfileThumbnail] AS [pt] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [web].[Profile] AS [pt_p] ON [pt].[ProfileID] = [pt_p].[ProfileID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileGroup] AS [pt_p_pg] ON [pt_p].[ProfileGroupID] = [pt_p_pg].[ProfileGroupID] ";
                }
                sqlCmdText += "WHERE [pt].[ProfileThumbnailID] = @ProfileThumbnailID;";

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

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

                ProfileThumbnailTable ptTable      = new ProfileThumbnailTable(query);
                ProfileTable          pt_pTable    = (this.Depth > 0) ? new ProfileTable(query) : null;
                ProfileGroupTable     pt_p_pgTable = (this.Depth > 1) ? new ProfileGroupTable(query) : null;


                ProfileGroup     pt_p_pgObject = (this.Depth > 1) ? pt_p_pgTable.CreateInstance() : null;
                Profile          pt_pObject    = (this.Depth > 0) ? pt_pTable.CreateInstance(pt_p_pgObject) : null;
                ProfileThumbnail ptObject      = ptTable.CreateInstance(pt_pObject);
                sqlReader.Close();

                return(ptObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pt", "loadinternal", "exception"), "ProfileThumbnail 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, "ProfileThumbnail", "Exception while loading ProfileThumbnail object from database. See inner exception for details.", ex);
            }
        }
        public ProfileThumbnail 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} " +
                             ProfileThumbnailTable.GetColumnNames("[pt]") +
                             (this.Depth > 0 ? "," + ProfileTable.GetColumnNames("[pt_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProfileGroupTable.GetColumnNames("[pt_p_pg]") : string.Empty) +
                             " FROM [web].[ProfileThumbnail] AS [pt] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [web].[Profile] AS [pt_p] ON [pt].[ProfileID] = [pt_p].[ProfileID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [web].[ProfileGroup] AS [pt_p_pg] ON [pt_p].[ProfileGroupID] = [pt_p_pg].[ProfileGroupID] ";
                }


                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("pt", "customload", "notfound"), "ProfileThumbnail 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);

                ProfileThumbnailTable ptTable      = new ProfileThumbnailTable(query);
                ProfileTable          pt_pTable    = (this.Depth > 0) ? new ProfileTable(query) : null;
                ProfileGroupTable     pt_p_pgTable = (this.Depth > 1) ? new ProfileGroupTable(query) : null;


                ProfileGroup     pt_p_pgObject = (this.Depth > 1) ? pt_p_pgTable.CreateInstance() : null;
                Profile          pt_pObject    = (this.Depth > 0) ? pt_pTable.CreateInstance(pt_p_pgObject) : null;
                ProfileThumbnail ptObject      = ptTable.CreateInstance(pt_pObject);
                sqlReader.Close();

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