Esempio n. 1
0
        protected override Gender 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 " +
                             GenderTable.GetColumnNames("[g]") +
                             " FROM [core].[Gender] AS [g] ";
                sqlCmdText += "WHERE [g].[GenderID] = @GenderID;";

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

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

                GenderTable gTable = new GenderTable(query);


                Gender gObject = gTable.CreateInstance();
                sqlReader.Close();

                return(gObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("g", "loadinternal", "exception"), "Gender 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, "Gender", "Exception while loading Gender object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 2
0
        public Gender 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} " +
                             GenderTable.GetColumnNames("[g]") +
                             " FROM [core].[Gender] AS [g] ";


                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("g", "customload", "notfound"), "Gender 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);

                GenderTable gTable = new GenderTable(query);


                Gender gObject = gTable.CreateInstance();
                sqlReader.Close();

                return(gObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("g", "customload", "exception"), "Gender 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, "Gender", "Exception while loading (custom/single) Gender object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 3
0
        protected override UserDetail 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 " +
                             UserDetailTable.GetColumnNames("[ud]") +
                             (this.Depth > 0 ? "," + UserTable.GetColumnNames("[ud_u]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserTypeTable.GetColumnNames("[ud_u_ut]") : string.Empty) +
                             (this.Depth > 0 ? "," + GenderTable.GetColumnNames("[ud_g]") : string.Empty) +
                             " FROM [core].[UserDetail] AS [ud] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[User] AS [ud_u] ON [ud].[UserID] = [ud_u].[UserID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserType] AS [ud_u_ut] ON [ud_u].[UserTypeID] = [ud_u_ut].[UserTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Gender] AS [ud_g] ON [ud].[GenderID] = [ud_g].[GenderID] ";
                }
                sqlCmdText += "WHERE [ud].[UserDetailID] = @UserDetailID;";

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

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

                UserDetailTable udTable      = new UserDetailTable(query);
                UserTable       ud_uTable    = (this.Depth > 0) ? new UserTable(query) : null;
                UserTypeTable   ud_u_utTable = (this.Depth > 1) ? new UserTypeTable(query) : null;
                GenderTable     ud_gTable    = (this.Depth > 0) ? new GenderTable(query) : null;


                UserType   ud_u_utObject = (this.Depth > 1) ? ud_u_utTable.CreateInstance() : null;
                User       ud_uObject    = (this.Depth > 0) ? ud_uTable.CreateInstance(ud_u_utObject) : null;
                Gender     ud_gObject    = (this.Depth > 0) ? ud_gTable.CreateInstance() : null;
                UserDetail udObject      = udTable.CreateInstance(ud_uObject, ud_gObject);
                sqlReader.Close();

                return(udObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ud", "loadinternal", "exception"), "UserDetail 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, "UserDetail", "Exception while loading UserDetail object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 4
0
        public List <UserDetail> 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} " +
                             UserDetailTable.GetColumnNames("[ud]") +
                             (this.Depth > 0 ? "," + UserTable.GetColumnNames("[ud_u]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserTypeTable.GetColumnNames("[ud_u_ut]") : string.Empty) +
                             (this.Depth > 0 ? "," + GenderTable.GetColumnNames("[ud_g]") : string.Empty) +
                             " FROM [core].[UserDetail] AS [ud] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[User] AS [ud_u] ON [ud].[UserID] = [ud_u].[UserID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserType] AS [ud_u_ut] ON [ud_u].[UserTypeID] = [ud_u_ut].[UserTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Gender] AS [ud_g] ON [ud].[GenderID] = [ud_g].[GenderID] ";
                }


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

                SqlQuery query = new SqlQuery(sqlReader);

                UserDetailTable udTable      = new UserDetailTable(query);
                UserTable       ud_uTable    = (this.Depth > 0) ? new UserTable(query) : null;
                UserTypeTable   ud_u_utTable = (this.Depth > 1) ? new UserTypeTable(query) : null;
                GenderTable     ud_gTable    = (this.Depth > 0) ? new GenderTable(query) : null;

                List <UserDetail> result = new List <UserDetail>();
                do
                {
                    UserType   ud_u_utObject = (this.Depth > 1) ? ud_u_utTable.CreateInstance() : null;
                    User       ud_uObject    = (this.Depth > 0) ? ud_uTable.CreateInstance(ud_u_utObject) : null;
                    Gender     ud_gObject    = (this.Depth > 0) ? ud_gTable.CreateInstance() : null;
                    UserDetail udObject      = (this.Depth > -1) ? udTable.CreateInstance(ud_uObject, ud_gObject) : null;
                    result.Add(udObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ud", "customloadmany", "exception"), "UserDetail 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, "UserDetail", "Exception while loading (custom/many) UserDetail object from database. See inner exception for details.", ex);
            }
        }