本文整理汇总了C#中DatabaseSchemaReader.DataSchema.DatabaseTable.AddColumn方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseTable.AddColumn方法的具体用法?C# DatabaseTable.AddColumn怎么用?C# DatabaseTable.AddColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseSchemaReader.DataSchema.DatabaseTable
的用法示例。
在下文中一共展示了DatabaseTable.AddColumn方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TriggerWithNoQuotes
public void TriggerWithNoQuotes()
{
//arrange
var osr = new OracleSchemaReader(ConnectionStrings.OracleHr, "System.Data.OracleClient");
var dt = new DatabaseTable();
dt
.AddColumn("ID")
.AddPrimaryKey()
.AddColumn("NAME");
dt.Triggers.Add(new DatabaseTrigger
{
//with spaces, line breaks
TriggerBody = @"BEGIN
SELECT MY_SEQ.NEXTVAL
INTO :NEW.ID
FROM DUAL;
END;"
});
//act
osr.PostProcessing(dt);
//assert
Assert.IsTrue(dt.HasAutoNumberColumn);
}
示例2: TestPostgreSqlColumnDefaults
public void TestPostgreSqlColumnDefaults()
{
//MigrationGenerator does not output default values for columns
//https://github.com/martinjw/dbschemareader/issues/11
//arrange
var gen = new DdlGeneratorFactory(SqlType.PostgreSql).MigrationGenerator();
gen.IncludeSchema = false;
var pkSeqName = "Seq_PK_Generator";
var pkSeq = new DatabaseSequence()
{
Name = pkSeqName,
MinimumValue = 1,
IncrementBy = 1,
};
//gen.AddSequence(pkSeq).Replace(";", " CACHE;");
var newTable = new DatabaseTable { Name = "TestTable" };
var idColumn = newTable.AddColumn("Id", DbType.Int64);
idColumn.AddPrimaryKey("PK_TestTable");
idColumn.DefaultValue = $"nextval('{pkSeqName}')";
var summaryColumn = newTable.AddColumn("Summary", DbType.String);
summaryColumn.Length = 100;
//act
var ddl = gen.AddTable(newTable);
//assert
//expected
/*
CREATE SEQUENCE "Seq_PK_Generator" INCREMENT BY 1 MINVALUE 1 CACHE;
CREATE TABLE "TestTable"
(
"Id" BIGINT NOT NULL, --default value missing
"Summary" VARCHAR (100) NOT NULL
);
ALTER TABLE "TestTable" ADD CONSTRAINT "PK_TestTable" PRIMARY KEY ("Id");
*/
Assert.IsTrue(ddl.IndexOf("BIGINT NOT NULL DEFAULT nextval('Seq_PK_Generator'),", StringComparison.OrdinalIgnoreCase) != -1, "default value should be included");
}
示例3: CreateTable
private static DatabaseTable CreateTable()
{
var table = new DatabaseTable();
table.Name = "Test";
table.AddColumn("A", DbType.Int32).AddPrimaryKey("PK_TEST")
.AddColumn("B", DbType.Int32)
.AddColumn("C", DbType.String).AddLength(10).AddNullable();
return table;
}
示例4: NoTriggers
public void NoTriggers()
{
//arrange
var osr = new OracleSchemaReader(ConnectionStrings.OracleHr, "System.Data.OracleClient");
var dt = new DatabaseTable();
dt
.AddColumn("ID")
.AddPrimaryKey()
.AddColumn("NAME");
//act
osr.PostProcessing(dt);
//assert
Assert.IsFalse(dt.HasAutoNumberColumn);
}
示例5: TestIndex
public void TestIndex()
{
//arrange
var settings = new CodeWriterSettings();
settings.CodeTarget = CodeTarget.PocoEntityCodeFirst;
settings.WriteCodeFirstIndexAttribute = true;
var classBuilder = new ClassBuilder();
var table = new DatabaseTable { Name = "Test" };
var nameColumn = table.AddColumn<int>("Id").AddPrimaryKey()
.AddColumn<string>("Name").AddNullable().AddIndex("IX_NAME");
var target = new DataAnnotationWriter(true, settings);
//act
target.Write(classBuilder, nameColumn);
var result = classBuilder.ToString().Trim(); //ignore lines
//assert
Assert.AreEqual("[Index(\"IX_NAME\")]", result);
}
示例6: TriggerWithQuotes
public void TriggerWithQuotes()
{
//arrange
var osr = new OracleSchemaReader(ConnectionStrings.OracleHr, "System.Data.OracleClient");
var dt = new DatabaseTable();
dt
.AddColumn("ID")
.AddPrimaryKey()
.AddColumn("NAME");
dt.Triggers.Add(new DatabaseTrigger
{
//generated by SqlDeveloper
TriggerBody = @"CREATE OR REPLACE TRIGGER ""DB"".""MYTRIGGER"" before insert on ""DB"".""TABLE1"" for each row begin if inserting then if :NEW.""ID"" is null then select MY_SEQ.nextval into :NEW.""ID"" from dual; end if; end if; end;"
});
//act
osr.PostProcessing(dt);
//assert
Assert.IsTrue(dt.HasAutoNumberColumn);
}
示例7: ReadProperty
private void ReadProperty(XElement property, DatabaseTable table)
{
var name = (string)property.Attribute("Name");
var type = (string)property.Attribute("Type");
var nullable = (bool?)property.Attribute("Nullable") ?? true;
var maxLength = (int?)property.Attribute("MaxLength");
var precision = (int?)property.Attribute("Precision");
var scale = (int?)property.Attribute("Scale");
var defaultValue = (string)property.Attribute("DefaultValue");
var storeGeneratedPattern = (string)property.Attribute("StoreGeneratedPattern");
if (type.EndsWith("(max)", StringComparison.OrdinalIgnoreCase))
{
type = type.Substring(0, type.Length - 5);
maxLength = -1;
}
//timestamp is a varbinary(8) computed
if (type == "binary" && maxLength == 8 && (string)property.Attribute("StoreGeneratedPattern") == "Computed")
{
type = "timestamp";
maxLength = null;
}
var column = table.AddColumn(name, type);
column.DefaultValue = defaultValue;
column.Length = maxLength;
column.Precision = precision;
column.Scale = scale;
column.Nullable = nullable;
if (storeGeneratedPattern == "Identity") column.IsAutoNumber = true;
FixColumn(column);
}
示例8: TestIndexNotNeededForPrimaryKey
public void TestIndexNotNeededForPrimaryKey()
{
//arrange
var settings = new CodeWriterSettings();
settings.CodeTarget = CodeTarget.PocoEntityCodeFirst;
settings.WriteCodeFirstIndexAttribute = true;
var classBuilder = new ClassBuilder();
var table = new DatabaseTable { Name = "Test" };
table.AddColumn<int>("Id").AddPrimaryKey().AddIndex("PK_TEST")
.AddColumn<string>("Category").AddNullable()
.AddColumn<string>("Name").AddNullable().AddIndex("IX_NAME")
;
var idColumn = table.PrimaryKeyColumn;
var target = new DataAnnotationWriter(true, settings);
//act
target.Write(classBuilder, idColumn);
var result = classBuilder.ToString().Trim(); //ignore lines
//assert
Assert.IsTrue(result.IndexOf("[Index", StringComparison.OrdinalIgnoreCase) == -1, "Should be just[Key]");
}