protected override TranslationValue 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 " + TranslationValueTable.GetColumnNames("[tv]") + (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk]") : string.Empty) + (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk_tk]") : string.Empty) + (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tv_tk_t]") : string.Empty) + (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tv_tk_l]") : string.Empty) + (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tv_tk_s]") : string.Empty) + (this.Depth > 0 ? "," + TranslationGroupKeyTable.GetColumnNames("[tv_tgk]") : string.Empty) + (this.Depth > 1 ? "," + TranslationGroupTable.GetColumnNames("[tv_tgk_tg]") : string.Empty) + " FROM [core].[TranslationValue] AS [tv] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[TranslationKey] AS [tv_tk] ON [tv].[TranslationKeyID] = [tv_tk].[TranslationKeyID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[TranslationKey] AS [tv_tk_tk] ON [tv_tk].[FallbackTranslationKeyID] = [tv_tk_tk].[TranslationKeyID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[Translation] AS [tv_tk_t] ON [tv_tk].[TranslationID] = [tv_tk_t].[TranslationID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[Language] AS [tv_tk_l] ON [tv_tk].[LanguageID] = [tv_tk_l].[LanguageID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[Service] AS [tv_tk_s] ON [tv_tk].[ServiceID] = [tv_tk_s].[ServiceID] "; } if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[TranslationGroupKey] AS [tv_tgk] ON [tv].[TranslationGroupKeyID] = [tv_tgk].[TranslationGroupKeyID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[TranslationGroup] AS [tv_tgk_tg] ON [tv_tgk].[TranslationGroupID] = [tv_tgk_tg].[TranslationGroupID] "; } sqlCmdText += "WHERE [tv].[TranslationValueID] = @TranslationValueID;"; SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand; sqlCmd.Parameters.AddWithValue("@TranslationValueID", id); SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader; if (!sqlReader.HasRows || !sqlReader.Read()) { IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "loadinternal", "notfound"), "TranslationValue 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); TranslationValueTable tvTable = new TranslationValueTable(query); TranslationKeyTable tv_tkTable = (this.Depth > 0) ? new TranslationKeyTable(query) : null; TranslationKeyTable tv_tk_tkTable = (this.Depth > 1) ? new TranslationKeyTable(query) : null; TranslationTable tv_tk_tTable = (this.Depth > 1) ? new TranslationTable(query) : null; LanguageTable tv_tk_lTable = (this.Depth > 1) ? new LanguageTable(query) : null; ServiceTable tv_tk_sTable = (this.Depth > 1) ? new ServiceTable(query) : null; TranslationGroupKeyTable tv_tgkTable = (this.Depth > 0) ? new TranslationGroupKeyTable(query) : null; TranslationGroupTable tv_tgk_tgTable = (this.Depth > 1) ? new TranslationGroupTable(query) : null; TranslationKey tv_tk_tkObject = (this.Depth > 1) ? tv_tk_tkTable.CreateInstance() : null; Translation tv_tk_tObject = (this.Depth > 1) ? tv_tk_tTable.CreateInstance() : null; Language tv_tk_lObject = (this.Depth > 1) ? tv_tk_lTable.CreateInstance() : null; Service tv_tk_sObject = (this.Depth > 1) ? tv_tk_sTable.CreateInstance() : null; TranslationKey tv_tkObject = (this.Depth > 0) ? tv_tkTable.CreateInstance(tv_tk_tkObject, tv_tk_tObject, tv_tk_lObject, tv_tk_sObject) : null; TranslationGroup tv_tgk_tgObject = (this.Depth > 1) ? tv_tgk_tgTable.CreateInstance() : null; TranslationGroupKey tv_tgkObject = (this.Depth > 0) ? tv_tgkTable.CreateInstance(tv_tgk_tgObject) : null; TranslationValue tvObject = tvTable.CreateInstance(tv_tkObject, tv_tgkObject); sqlReader.Close(); return(tvObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "loadinternal", "exception"), "TranslationValue 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, "TranslationValue", "Exception while loading TranslationValue object from database. See inner exception for details.", ex); } }
public List <TranslationValue> 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} " + TranslationValueTable.GetColumnNames("[tv]") + (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk]") : string.Empty) + (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk_tk]") : string.Empty) + (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tv_tk_t]") : string.Empty) + (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tv_tk_l]") : string.Empty) + (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tv_tk_s]") : string.Empty) + (this.Depth > 0 ? "," + TranslationGroupKeyTable.GetColumnNames("[tv_tgk]") : string.Empty) + (this.Depth > 1 ? "," + TranslationGroupTable.GetColumnNames("[tv_tgk_tg]") : string.Empty) + " FROM [core].[TranslationValue] AS [tv] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[TranslationKey] AS [tv_tk] ON [tv].[TranslationKeyID] = [tv_tk].[TranslationKeyID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[TranslationKey] AS [tv_tk_tk] ON [tv_tk].[FallbackTranslationKeyID] = [tv_tk_tk].[TranslationKeyID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[Translation] AS [tv_tk_t] ON [tv_tk].[TranslationID] = [tv_tk_t].[TranslationID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[Language] AS [tv_tk_l] ON [tv_tk].[LanguageID] = [tv_tk_l].[LanguageID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[Service] AS [tv_tk_s] ON [tv_tk].[ServiceID] = [tv_tk_s].[ServiceID] "; } if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[TranslationGroupKey] AS [tv_tgk] ON [tv].[TranslationGroupKeyID] = [tv_tgk].[TranslationGroupKeyID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[TranslationGroup] AS [tv_tgk_tg] ON [tv_tgk].[TranslationGroupID] = [tv_tgk_tg].[TranslationGroupID] "; } 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("tv", "customloadmany", "notfound"), "TranslationValue 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 <TranslationValue>()); } SqlQuery query = new SqlQuery(sqlReader); TranslationValueTable tvTable = new TranslationValueTable(query); TranslationKeyTable tv_tkTable = (this.Depth > 0) ? new TranslationKeyTable(query) : null; TranslationKeyTable tv_tk_tkTable = (this.Depth > 1) ? new TranslationKeyTable(query) : null; TranslationTable tv_tk_tTable = (this.Depth > 1) ? new TranslationTable(query) : null; LanguageTable tv_tk_lTable = (this.Depth > 1) ? new LanguageTable(query) : null; ServiceTable tv_tk_sTable = (this.Depth > 1) ? new ServiceTable(query) : null; TranslationGroupKeyTable tv_tgkTable = (this.Depth > 0) ? new TranslationGroupKeyTable(query) : null; TranslationGroupTable tv_tgk_tgTable = (this.Depth > 1) ? new TranslationGroupTable(query) : null; List <TranslationValue> result = new List <TranslationValue>(); do { TranslationKey tv_tk_tkObject = (this.Depth > 1) ? tv_tk_tkTable.CreateInstance() : null; Translation tv_tk_tObject = (this.Depth > 1) ? tv_tk_tTable.CreateInstance() : null; Language tv_tk_lObject = (this.Depth > 1) ? tv_tk_lTable.CreateInstance() : null; Service tv_tk_sObject = (this.Depth > 1) ? tv_tk_sTable.CreateInstance() : null; TranslationKey tv_tkObject = (this.Depth > 0) ? tv_tkTable.CreateInstance(tv_tk_tkObject, tv_tk_tObject, tv_tk_lObject, tv_tk_sObject) : null; TranslationGroup tv_tgk_tgObject = (this.Depth > 1) ? tv_tgk_tgTable.CreateInstance() : null; TranslationGroupKey tv_tgkObject = (this.Depth > 0) ? tv_tgkTable.CreateInstance(tv_tgk_tgObject) : null; TranslationValue tvObject = (this.Depth > -1) ? tvTable.CreateInstance(tv_tkObject, tv_tgkObject) : null; result.Add(tvObject); } while (sqlReader.Read()); sqlReader.Close(); return(result); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "customloadmany", "exception"), "TranslationValue 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, "TranslationValue", "Exception while loading (custom/many) TranslationValue object from database. See inner exception for details.", ex); } }