Exemplo n.º 1
0
        /// <summary>
        /// Computes a column name which is unique in the given class mapping.
        /// </summary>
        /// <param name="theFieldName">The field name, the column name is derived from.</param>
        /// <param name="isOidField">Specifies, if the the field is used as Oid for the given class.</param>
        /// <returns>A string representing a column name.</returns>
        public string ColumnNameFromFieldName(string theFieldName, bool isOidField)
        {
            if (theFieldName[0] == '<')
            {
                int q = theFieldName.IndexOf('>');
                if (q > -1)
                {
                    return(theFieldName.Substring(1, q - 1));
                }
            }

            string[] strarr = theFieldName.Split('.');
            for (int i = 0; i < strarr.Length; i++)
            {
                if (strarr[i].StartsWith("_"))
                {
                    strarr[i] = strarr[i].Substring(1);
                }
                if (strarr[i].StartsWith("m_"))
                {
                    strarr[i] = strarr[i].Substring(2);
                }
                if (char.IsLower(strarr[i][0]))
                {
                    strarr[i] = strarr[i].Substring(0, 1).ToUpper() + strarr[i].Substring(1);
                }
            }
            string columnName = string.Empty;

            for (int i = 0; i < strarr.Length; i++)
            {
                if (i > 0)
                {
                    columnName += "_";
                }
                columnName = columnName + strarr[i];
            }

            string newColumnName = columnName;
            int    index         = 0;

            while (this.FindColumn(newColumnName) != null ||
                   !isOidField && Oid.FindColumn(newColumnName) != null)
            {
                index++;
                newColumnName = columnName + index.ToString();
            }
            return(newColumnName);
        }