本文整理汇总了C#中ITable.AddColumn方法的典型用法代码示例。如果您正苦于以下问题:C# ITable.AddColumn方法的具体用法?C# ITable.AddColumn怎么用?C# ITable.AddColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITable
的用法示例。
在下文中一共展示了ITable.AddColumn方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public void Setup()
{
set = new MappingSetImpl();
entity = new EntityImpl("Entity1");
set.EntitySet.AddEntity(entity);
table = new Table("Table1");
table.AddColumn(new Column("Street"));
set.Database.AddTable(table);
spec = new ComponentSpecificationImpl("Address");
spec.AddProperty(new ComponentPropertyImpl("Street"));
set.EntitySet.AddComponentSpecification(spec);
component = spec.CreateImplementedComponentFor(entity, "HomeAddress");
set.ChangeMappingFor(component.Properties[0]).To(table.Columns[0]);
}
示例2: SetupProperties
private static void SetupProperties(ITable Table, IMapping Mapping)
{
Contract.Requires<ArgumentNullException>(Mapping != null, "Mapping");
Contract.Requires<ArgumentNullException>(Table != null, "Table");
Contract.Requires<ArgumentNullException>(Mapping.IDProperties != null, "Mapping.IDProperties");
foreach (IProperty Property in Mapping.IDProperties)
{
Table.AddColumn(Property.FieldName,
Property.Type.To(DbType.Int32),
Property.MaxLength,
Property.NotNull,
Property.AutoIncrement,
Property.Index,
true,
Property.Unique,
"",
"",
"");
}
foreach (IProperty Property in Mapping.Properties)
{
if (!(Property is IManyToMany || Property is IManyToOne || Property is IMap || Property is IIEnumerableManyToOne || Property is IListManyToMany || Property is IListManyToOne))
{
Table.AddColumn(Property.FieldName,
Property.Type.To(DbType.Int32),
Property.MaxLength,
!Property.NotNull,
Property.AutoIncrement,
Property.Index,
false,
Property.Unique,
"",
"",
"");
}
}
}
示例3: GetColumns
private void GetColumns(ITable table)
{
Type uniDBType = typeof(SQLServer.UniDbTypes);
DataRow[] columnRows = connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}'", table.Name.Replace("'", "''"), table.Schema));
foreach (DataRow columnRow in columnRows)
{
bool isReadOnly = false;
if (Slyce.Common.Utility.StringsAreEqual((string)columnRow["DATA_TYPE"], "timestamp", false))
{
isReadOnly = true;
}
Column column = new Column();
column.Name = (string)columnRow["COLUMN_NAME"];
column.IsUserDefined = false;
column.Parent = table;
column.IsIdentity = columnRow["IsIdentity"] is DBNull ? false : (Convert.ToInt32(columnRow["IsIdentity"])) == 1;
column.OrdinalPosition = Convert.ToInt32(columnRow["ORDINAL_POSITION"]);
column.IsNullable = Slyce.Common.Utility.StringsAreEqual((string)columnRow["IS_NULLABLE"], "YES", false);
column.OriginalDataType = (string)columnRow["DATA_TYPE"];
column.Size = columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH") //|| column.Datatype == "ntext" || column.Datatype == "text" // ntext/text returns useless length
? 0
: Convert.ToInt64(columnRow["CHARACTER_MAXIMUM_LENGTH"]);
column.InPrimaryKey = connector.DoesColumnHaveConstraint(column, "PRIMARY KEY");
column.IsUnique = connector.DoesColumnHaveConstraint(column, "UNIQUE");
column.Default = columnRow.IsNull("COLUMN_DEFAULT") ? "" : (string)columnRow["COLUMN_DEFAULT"];
column.IsReadOnly = isReadOnly;
column.Precision = columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]);
column.Scale = columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]);
column.ResetDefaults();
table.AddColumn(column);
}
}
示例4: SetupProperties
private static void SetupProperties(ITable Table, IMapping Mapping)
{
Contract.Requires<ArgumentNullException>(Mapping != null, "Mapping");
Contract.Requires<ArgumentNullException>(Table != null, "Table");
Contract.Requires<ArgumentNullException>(Mapping.IDProperties != null, "Mapping.IDProperties");
Mapping.IDProperties
.ForEach(x =>
{
Table.AddColumn(x.FieldName,
x.Type.To(DbType.Int32),
x.MaxLength,
x.NotNull,
x.AutoIncrement,
x.Index,
true,
x.Unique,
"",
"",
"");
});
Mapping.Properties
.Where(x => !(x is IMultiMapping || x is ISingleMapping || x is IMap))
.ForEach(x =>
{
Table.AddColumn(x.FieldName,
x.Type.To(DbType.Int32),
x.MaxLength,
!x.NotNull,
x.AutoIncrement,
x.Index,
false,
x.Unique,
"",
"",
"");
});
}
示例5: CloneColumn
private static IColumn CloneColumn(ITable primaryTable, ITable foreignTable, IColumn column, string columnNamePrefix)
{
var newColumn = column.Clone();
var name = columnNamePrefix + primaryTable.Name + "_" + column.Name;
newColumn.Name = name.GetNextName(foreignTable.Columns.Select(c => c.Name));
foreignTable.AddColumn(newColumn);
return newColumn;
}
示例6: GetColumns
private void GetColumns(ITable table)
{
Type uniDBType = typeof(SQLServer.UniDbTypes);
string cleanTableName = table.Name.Replace("'", "''");
if (!connector.ColumnsBySchema.ContainsKey(table.Schema))
return;
if (!connector.ColumnsBySchema[table.Schema].ContainsKey(cleanTableName))
return;
List<DataRow> columnRows = connector.ColumnsBySchema[table.Schema][cleanTableName];
foreach (DataRow columnRow in columnRows)
{
bool isReadOnly = false;
if (Slyce.Common.Utility.StringsAreEqual((string)columnRow["DATA_TYPE"], "timestamp", false))
{
isReadOnly = true;
}
Column column = new Column();
column.Name = (string)columnRow["COLUMN_NAME"];
column.IsUserDefined = false;
column.Parent = table;
column.IsIdentity = columnRow["IsIdentity"] is DBNull ? false : (Convert.ToInt32(columnRow["IsIdentity"])) == 1;
column.OrdinalPosition = Convert.ToInt32(columnRow["ORDINAL_POSITION"]);
column.IsNullable = ((string)columnRow["IS_NULLABLE"]).StartsWith("Y", StringComparison.InvariantCultureIgnoreCase);
column.Precision = columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]);
column.Scale = columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]);
column.OriginalDataType = (string)columnRow["DATA_TYPE"];
column.Size = columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH") //|| column.Datatype == "ntext" || column.Datatype == "text" // ntext/text returns useless length
? 0
: Convert.ToInt64(columnRow["CHARACTER_MAXIMUM_LENGTH"]);
column.InPrimaryKey = connector.DoesColumnHaveConstraint(column, "PRIMARY KEY");
column.IsUnique = connector.DoesColumnHaveConstraint(column, "UNIQUE");
column.Default = columnRow.IsNull("COLUMN_DEFAULT") ? "" : (string)columnRow["COLUMN_DEFAULT"];
column.IsReadOnly = isReadOnly;
column.ResetDefaults();
table.AddColumn(column);
}
}
示例7: SetupColumns
/// <summary>
/// Setups the columns.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="item">The item.</param>
private static void SetupColumns(ITable table, dynamic item)
{
if (item == null)
throw new ArgumentNullException(nameof(item));
if (table == null)
throw new ArgumentNullException(nameof(table));
if (table.ContainsColumn(item.Column))
{
table.AddForeignKey(item.Column, item.FOREIGN_KEY_TABLE, item.FOREIGN_KEY_COLUMN);
}
else
{
table.AddColumn<string>(item.Column,
Utilities.DataTypes.TypeConversionExtensions.To(Utilities.DataTypes.TypeConversionExtensions.To<string, SqlDbType>(item.COLUMN_TYPE), DbType.Int32),
(item.COLUMN_TYPE == "nvarchar") ? item.MAX_LENGTH / 2 : item.MAX_LENGTH,
item.IS_NULLABLE,
item.IS_IDENTITY,
item.IS_INDEX != 0,
!string.IsNullOrEmpty(item.PRIMARY_KEY),
!string.IsNullOrEmpty(item.UNIQUE),
item.FOREIGN_KEY_TABLE,
item.FOREIGN_KEY_COLUMN,
item.DEFAULT_VALUE);
}
}
示例8: SetupStoredProcedures
/// <summary>
/// Setups the stored procedures.
/// </summary>
/// <param name="storedProcedure">The stored procedure.</param>
/// <param name="item">The item.</param>
private static void SetupStoredProcedures(ITable storedProcedure, dynamic item)
{
if (storedProcedure == null)
throw new ArgumentNullException(nameof(storedProcedure));
if (item == null)
throw new ArgumentNullException(nameof(item));
string Type = item.TYPE;
string Name = item.NAME;
int Length = item.LENGTH;
if (Type == "nvarchar")
Length /= 2;
string Default = item.DEFAULT_VALUE;
storedProcedure.AddColumn<string>(Name, Type.To<string, SqlDbType>().To(DbType.Int32), Length, DefaultValue: Default);
}