Example #1
0
        public static List <TableColumn> BuildTableColumns(List <Column> columns, string tableName)
        {
            var list = new List <TableColumn>();

            foreach (var item in columns)
            {
                var col = new TableColumn();
                col.AllowNull    = item.IsNullable == YesNoOption.YES;
                col.DataType     = item.DataType;
                col.DefaultValue = item.ColumnDefault;
                col.Identity     = item.AutoIncrementBy > 1;
                Int16 colLength = 0;
                if (Int16.TryParse(item.CharacterMaxLength.ToString(), out colLength))
                {
                    col.Length = colLength;
                }
                if (TableDataType.IsLengthFixed(item.DataType))
                {
                    col.Length = TableDataType.GetDefaultLength(item.DataType);
                }
                col.Name      = item.ColumnName;
                col.Precision = Byte.Parse(item.NumericPrecision.ToString());
                //TODO Detect!
                col.PrimaryKey = false;
                col.Scale      = Byte.Parse(item.NumericScale.ToString());
                list.Add(col);
            }
            return(list);
        }
Example #2
0
 public static string ValidateColumns(List <TableColumn> columns)
 {
     foreach (var item in columns)
     {
         if (string.IsNullOrEmpty(item.DataType))
         {
             return("Data type is required");
         }
         if (string.IsNullOrEmpty(item.Name))
         {
             return("Column name is required");
         }
         if (!TableDataType.IsLengthFixed(item.DataType))
         {
             if (item.Length < TableDataType.GetMinLength(item.DataType) ||
                 item.Length > TableDataType.GetMaxLength(item.DataType))
             {
                 return(string.Format("Column length of colum {0} must be between {1} and {2}",
                                      item.Name, TableDataType.GetMinLength(item.DataType), TableDataType.GetMaxLength(item.DataType)));
             }
         }
         //Check for duplicates
         if (columns.Select(x => x.Name).ToList()
             .GroupBy(x => x)
             .Where(x => x.Count() > 1)
             .Select(x => x.Key).ToList().Count > 0)
         {
             return("Duplicate column names not allowed");
         }
         //Check for only 1 identity column
         var identityCols = columns.Where(x => x.Identity).ToList();
         if (identityCols.Count > 1)
         {
             return("Only a single Identity column allowed");
         }
     }
     return(string.Empty);
 }