Exemple #1
0
        private void WriteSingleReadData(string resultClassName, DatabaseResultSet result)
        {
            //single result set
            using (_cb.BeginNest("private static void ReadData(IDataReader rdr, ICollection<" + resultClassName + "> result)"))
            {
                using (_cb.BeginNest("while (rdr.Read())"))
                {
                    _cb.AppendLine("var record = new " + resultClassName + "();");
                    for (int index = 0; index < result.Columns.Count; index++)
                    {
                        var column   = result.Columns[index];
                        var name     = column.NetName ?? NameFixer.ToPascalCase(column.Name);
                        var dt       = column.DataType;
                        var dataType = dt != null?dt.NetCodeName(column) : column.DbDataType;

                        if (!string.Equals(dataType, "String", StringComparison.OrdinalIgnoreCase) && !dataType.EndsWith("[]", StringComparison.OrdinalIgnoreCase))
                        {
                            dataType += "?"; //nullable
                        }
                        //manage DbNull
                        _cb.AppendLine("record." + name + " = (" + dataType + ")FixNull(rdr[" + index + "]);");
                    }
                    _cb.AppendLine("result.Add(record);");
                }
            }
        }
Exemple #2
0
        public static string ArgumentCamelCaseName(DatabaseArgument argument)
        {
            var name = argument.NetName;

            if (string.IsNullOrEmpty(name))
            {
                name             = NameFixer.ToPascalCase(argument.Name);
                argument.NetName = name;
            }
            return(Char.ToLowerInvariant(name[0])
                   + (name.Length > 1 ? name.Substring(1) : string.Empty));
        }
Exemple #3
0
        private void WriteProperties(DatabaseResultSet result)
        {
            foreach (var column in result.Columns)
            {
                if (string.IsNullOrEmpty(column.NetName))
                {
                    column.NetName = NameFixer.ToPascalCase(column.Name);
                }
                var dataType = TranslateDataTypeToCSharp(column.DbDataType);

                if (!string.Equals(dataType, "String", StringComparison.OrdinalIgnoreCase) &&
                    !dataType.EndsWith("[]", StringComparison.OrdinalIgnoreCase))
                {
                    dataType += "?"; //nullable
                }
                _cb.AppendAutomaticProperty(dataType, column.NetName);
            }
        }
        public void ToPascalCaseTest()
        {
            //ARRANGE

            var dict = new Dictionary <string, string>();

            //pascalcase
            dict.Add("START_DATE", "StartDate");   //underscore
            dict.Add("EMPLOYEE_ID", "EmployeeId");
            dict.Add("EMPLOYEE ID", "EmployeeId"); //spaces
            dict.Add("CategoryId", "CategoryId");  //if mixed case, preserve it
            //singularization
            dict.Add("Cars", "Car");
            dict.Add("rates", "Rate");
            dict.Add("Boxes", "Box");
            dict.Add("Categories", "Category");
            dict.Add("queries", "Query");
            dict.Add("Statuses", "Status");
            dict.Add("People", "Person");
            //complex titlecase
            dict.Add("les naufragés d'ythaq", "LesNaufragésDythaq");
            dict.Add("Database_IO", "DatabaseIO"); //mixed case with uppercase acronym
            //Id recognition
            dict.Add("CategoryID", "CategoryId");
            //weird db names
            dict.Add("$NAME", "Name");

            foreach (var item in dict)
            {
                var name     = item.Key;
                var expected = item.Value;

                //ACT
                var actual = NameFixer.ToPascalCase(name);

                //ASSERT
                Assert.AreEqual(expected, actual);
            }
        }
Exemple #5
0
 public SprocLogic(DatabaseStoredProcedure storedProcedure)
 {
     _storedProcedure = storedProcedure;
     _className       = _storedProcedure.NetName ?? (_storedProcedure.NetName = NameFixer.ToPascalCase(_storedProcedure.Name));
 }