Exemple #1
0
 public IDataReader ExecuteReader(CodeGenQuery query)
 {
     using (DbCommand command = Provider.FetchCommand(query))
     {
         return(ExecuteReader(command));
     }
 }
Exemple #2
0
        private string GenerateEnum(TableDefinition table)
        {
            StringBuilder builder = new StringBuilder();

            try
            {
                using (IDataReader reader = session.ExecuteReader(CodeGenQuery.From(table)))
                {
                    int count = 0;
                    while (reader.Read())
                    {
                        string name = reader.GetString(table.ValueOrdinal);
                        if (Compare.IsNullOrEmpty(name))
                        {
                            name = "Empty";
                        }

                        if (count > 0)
                        {
                            builder.AppendLine();
                        }
                        builder.AppendLine(Indent.One + "/// <summary>");
                        builder.AppendLine(Indent.One + "/// " + name);
                        builder.AppendLine(Indent.One + "/// </summary>");
                        builder.AppendLine(Indent.One + "[EnumDescription(\"" + name + "\")]");
                        builder.AppendLine(Indent.One + CodeFormat.ToPascalCase(name, CodeFormatOptions.RemoveFKPrefix) + " = " + Convert.ToInt32(reader[table.KeyOrdinal]) + ",");
                        count++;
                    }

                    builder.Remove(builder.Length - Environment.NewLine.Length - 1, 1);
                }
                return(Templates.Enum
                       .Replace(Tokens.ClassName, table.Name)
                       .Replace(Tokens.SchemaName, table.Owner)
                       .Replace(Tokens.TableName, table.Name)
                       .Replace(Tokens.EnumValues, builder.ToString()));
            }
            catch (InvalidCastException ex)
            {
                builder.AppendLine("/*");
                builder.AppendLine("While attempting to generate an enum, this table failed with the following exception:");
                builder.AppendLine(ex.ToString());
                builder.AppendLine("*/");
                builder.AppendLine(classProcessor.GenerateClass(table));
            }
            return(builder.ToString());
        }