Пример #1
0
        public List<DbTable> GetDbTables(string database)
        {
            if (string.IsNullOrEmpty(database))
            {
                throw new ArgumentNullException("database");
            }

            var dbTables = new List<DbTable>();

            try
            {
                var commandText = string.Format(getDbTables, database);

                var dataReader = this.sqlServer.ExecuteDataReader(CommandType.Text, commandText, null, null);
                while (dataReader.Read())
                {
                    var dbTable = new DbTable
                    {
                        Id = dataReader[0].ToString(),
                        Name = dataReader[1].ToString()
                    };

                    commandText = string.Format(getDbTableSummary, database, dbTable.Name);
                    var dbTableSummary = this.sqlServer.ExecuteScalar(CommandType.Text, commandText, null, null);
                    if (dbTableSummary == null)
                    {
                        dbTableSummary = "The " + dbTable.Name + " class.";
                    }

                    dbTable.Summary = dbTableSummary.ToString();
                    dbTable.DbColumns = this.GetDbColumns(database, dbTable.Name);

                    dbTables.Add(dbTable);
                }

                dataReader.Close();
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return dbTables;
        }
Пример #2
0
        public string GetEntityContent(DbTable dbTable)
        {
            if (dbTable == null)
            {
                throw new ArgumentNullException("dbTable");
            }

            var stringBuilder = new StringBuilder();

            var headerString = this.FileHeader(dbTable.Summary);

            var nameSpaceString = "\r\n" + "namespace " + this.NameSpace + "\r\n" + "{";

            var usingListString = string.Empty;
            if (!string.IsNullOrEmpty(this.UsingList))
            {
                usingListString = "\r\n    " + this.UsingList + "\r\n";
            }

            var classSummaryString = this.GetClassSummary(dbTable.Summary);
            var classCodeString = this.GetClassCode() + "\r\n    {\r\n";

            var properties = new StringBuilder();
            foreach (var dbColumn in dbTable.DbColumns)
            {
                var propertySummary = this.GetPropertySummary(dbColumn.Summary);
                var propertyCode = "        " + this.GetPropertyCode(dbColumn);

                properties.Append(propertySummary);
                properties.Append(propertyCode);
                properties.Append("\r\n");
            }

            var propertyString = string.Format(PublicProperties, properties);

            stringBuilder.Append(headerString);
            stringBuilder.Append(nameSpaceString);
            stringBuilder.Append(usingListString);
            stringBuilder.Append(classSummaryString);
            stringBuilder.Append(classCodeString);
            stringBuilder.Append(propertyString);
            stringBuilder.Append("\r\n    }\r\n}");

            return stringBuilder.ToString();
        }