/// <summary> /// Adds a column. /// </summary> /// <param name="databaseTable">The database table.</param> /// <param name="columnName">Name of the column.</param> /// <param name="dataType">Type of the data. Eg "INT", "VARCHAR(10)", "DECIMAL(10,2)"</param> /// <param name="columnInitialization">The column initialization.</param> /// <returns></returns> public static DatabaseColumn AddColumn(this DatabaseTable databaseTable, string columnName, string dataType, Action <DatabaseColumn> columnInitialization) { if (databaseTable == null) { throw new ArgumentNullException("databaseTable", "databaseTable must not be null"); } if (String.IsNullOrEmpty(columnName)) { throw new ArgumentNullException("columnName", "columnName must not be null"); } if (String.IsNullOrEmpty(dataType)) { throw new ArgumentNullException("dataType", "dataType must not be null"); } if (columnInitialization == null) { throw new ArgumentNullException("columnInitialization", "columnInitialization must not be null"); } var column = DataTypeConverter.ParseDataType(dataType); column.Name = columnName; AddColumn(databaseTable, column); columnInitialization(column); return(column); }
public void TestInt() { var column = DataTypeConverter.ParseDataType("INT"); Assert.AreEqual("INT", column.DbDataType); Assert.IsNull(column.Length); Assert.IsNull(column.Precision); }
public void TestDecimal() { var column = DataTypeConverter.ParseDataType("DECIMAL ( 10 )"); Assert.AreEqual("DECIMAL", column.DbDataType); Assert.AreEqual(null, column.Length); Assert.AreEqual(10, column.Precision); }
public void TestVarCharMax() { var column = DataTypeConverter.ParseDataType("VARCHAR(MAX)"); Assert.AreEqual("VARCHAR", column.DbDataType); Assert.AreEqual(-1, column.Length); Assert.IsNull(column.Precision); }