Ejemplo n.º 1
0
        /// <summary>
        /// Sample:
        /// [dbo].[Events_SelectSingle]
        /// </summary>
        public static string GenerateSqlStoredProcName(string tableName, eStoredProcType procType, IEnumerable <string> selectedFields)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentException("Cannot generate stored procedure name without a table name.");
            }

            string suffix;
            string selectedFieldsString = (selectedFields == null) ? string.Empty : string.Join(string.Empty, selectedFields);

            switch (procType)
            {
            case eStoredProcType.SelectSingle: suffix = string.Format(_SelectSingleByXSpSuffix, selectedFieldsString); break;

            case eStoredProcType.SelectMany: suffix = _SelectManySpSuffix; break;

            case eStoredProcType.SelectManyByX: suffix = string.Format(_SelectManyByXSpSuffix, selectedFieldsString); break;

            case eStoredProcType.SelectAll: suffix = _SelectAllSpSuffix; break;

            case eStoredProcType.SearchPaged: suffix = _SearchPagedSpSuffix; break;

            case eStoredProcType.Insert: suffix = _InsertSingleSpSuffix; break;

            case eStoredProcType.Update: suffix = _UpdateSpSuffix; break;

            case eStoredProcType.UpdateInsert: suffix = _UpdateInsertSpSuffix; break;

            case eStoredProcType.DelSingle: suffix = _DelSingleSpSuffix; break;

            case eStoredProcType.DelMany: suffix = _DelManySpSuffix; break;

            case eStoredProcType.DelAll: suffix = _DelAllSpSuffix; break;

            default:
                throw new Exception($"StoredProcType unknown: {procType}");
            }

            // tried title case here, gets a little odd.
            tableName = tableName.Replace(" ", "_");
            tableName = $"{_SpNamePrefix}{tableName}_{suffix}";
            tableName = tableName.Replace("__", "_");

            return(tableName);
        }
Ejemplo n.º 2
0
        public static string GenerateSqlStoredProcName(string table_name, eStoredProcType proc_type, List<string> select_fields)
        {
            // Sample:
                // sp_tb_lookup_events_SelectSingle

                if (string.IsNullOrEmpty(table_name))
                    throw new Exception("Cannot generate stored procedure name without a table name.");

                string suffix                   = string.Empty;
                string selected_fields_string   = string.Empty;

                // in the event that we are building a name dynamically
                if (select_fields != null)
                {
                    foreach (var item in select_fields)
                        selected_fields_string += item;
                }

                switch (proc_type)
                {
                    case eStoredProcType.SelectSingle:   suffix = s_SelectSingleSpSuffix; break;
                    case eStoredProcType.SelectMany:     suffix = s_SelectManySpSuffix; break;
                    case eStoredProcType.SelectManyByX:  suffix = string.Format(s_SelectManyByXSpSuffix, selected_fields_string); break;
                    case eStoredProcType.SelectAll:      suffix = s_SelectAllSpSuffix; break;
                    case eStoredProcType.SelectAllPag:   suffix = s_SelectAllPagSpSuffix; break;
                    case eStoredProcType.Insert:         suffix = s_InsertSingleSpSuffix; break;
                    case eStoredProcType.Update:         suffix = s_UpdateSpSuffix; break;
                    case eStoredProcType.UpdateInsert:   suffix = s_UpdateInsertSpSuffix; break;
                    case eStoredProcType.DelSingle:      suffix = s_DelSingleSpSuffix; break;
                    case eStoredProcType.DelMany:        suffix = s_DelManySpSuffix; break;
                    case eStoredProcType.DelAll:         suffix = s_DelAllSpSuffix; break;
                    case eStoredProcType.CountAll:       suffix = s_CountAllSpSuffix; break;
                    case eStoredProcType.CountSearch:    suffix = s_CountSearchSpSuffix; break;

                    default:
                        throw new Exception("StoredProcType unknown: " + proc_type.ToString());
                }

                //table_name = NameFormatter.ToTitleCase(table_name);
                table_name = table_name.Replace(" ", "_");
                table_name = s_SpNamePrefix + table_name + "_" + suffix;
                table_name = table_name.Replace("__", "_");

                return table_name;
        }