Пример #1
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);
            }
        }
Пример #2
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);
            }
        }