本文整理汇总了C#中Database.AddTable方法的典型用法代码示例。如果您正苦于以下问题:C# Database.AddTable方法的具体用法?C# Database.AddTable怎么用?C# Database.AddTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.AddTable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillDatabase
/// <summary>
/// Fills the database.
/// </summary>
/// <param name="values">The values.</param>
/// <param name="database">The database.</param>
public void FillDatabase(IEnumerable<dynamic> values, Database database)
{
if (database == null)
throw new ArgumentNullException(nameof(database));
if (values == null || values.Count() == 0)
return;
foreach (dynamic Item in values)
{
string TableName = Item.TABLE_NAME;
string TableType = Item.TABLE_TYPE;
if (TableType == "BASE TABLE")
database.AddTable(TableName);
else if (TableType == "VIEW")
database.AddView(TableName);
}
}
示例2: EnsureMigrationHistorySchemaExists
/// <summary>
/// Ensures that the schema for the migration history exists.
/// </summary>
/// <param name="context">The context.</param>
protected virtual void EnsureMigrationHistorySchemaExists(MigrationContext context)
{
if (schemaDone) return;
//
// Check if schema already exists
//
bool error;
InternalRetrieveHistory(context, out error);
if (error)
{
//
// Try to create schema ... if it already exits the
// SQL commands will simply fail
//
Database model = new Database(null);
Table t = model.AddTable(TableName);
{
t.AddColumn(DateColumnName, SqlTypes.DateTime).NotNull();
t.AddColumn(VersionColumnName, SqlTypes.BigInt).NotNull();
t.AddColumn(DirectionColumnName, SqlTypes.TinyInt).NotNull();
}
foreach (string sql in context.SqlProvider.GenerateSqlCommands(model))
{
try
{
context.SqlProcessor.ProcessMigrationStatement(context, sql);
}
catch
{
// The schema probaly already exists,
// just ignore the exception
break;
}
}
}
schemaDone = true;
}
示例3: SendPod
public void SendPod(DatabaseUtilities.Table tab, string name)
{
Debug.Log("STARTING TEST...");
Database test = new Database();
test.SetName(name);
test.tables = new List<DatabaseUtilities.Table>();
test.AddTable(tab);
BuildPod(test);
/*DatabaseUtilities.Table t = new DatabaseUtilities.Table();
t.SetName("Dean");
t.SetId("T34");
t.columns = new List<DatabaseUtilities.Column>();
DatabaseUtilities.Column c = new DatabaseUtilities.Column();
c.SetName("Sam");
c.SetId("12");
c.SetColor(DatabaseBuilder.GetRandomColor());
c.fields = new List<string>();
c.AddField("Dogs");
DatabaseUtilities.Column c2 = new DatabaseUtilities.Column();
c2.SetName("Sammy");
c2.SetId("1234");
c2.SetColor(DatabaseBuilder.GetRandomColor());
c2.fields = new List<string>();
c2.AddField("Cats");
t.AddColumn(c);
t.AddColumn(c2);
test.AddTable(t);
*/
}
示例4: InitializeTarget
public void InitializeTarget()
{
MigrationContext context = new MigrationContext();
Database db = new Database(context);
Target = db.AddTable("Table");
}
示例5: TypeTest
public void TypeTest()
{
Database db = new Database(new MigrationContext());
var table = db.AddTable("MyTable");
var c1 = table.AlterColumn("MyColumn1").Type(SqlTypes.Date);
var c2 = table.AlterColumn("MyColumn2").Type(typeof(int));
var c3 = table.AlterColumn("MyColumn3").Type(SqlTypes.VarChar, 32);
var c4 = table.AlterColumn("MyColumn4").Type(typeof(decimal), 10, 2);
var c5 = table.AlterColumn("MyColumn5").Type(typeof(string), 64);
var c6 = table.AlterColumn("MyColumn6").Type(SqlTypes.Decimal, 18, 4);
Assert.AreEqual("MyColumn1", c1.Name);
Assert.AreEqual(SqlTypes.Date, c1.DataType);
Assert.AreEqual(true, c1.IsNullable);
Assert.AreEqual(null, c1.Length);
Assert.AreEqual(null, c1.Precision);
Assert.AreEqual(null, c1.Scale);
Assert.AreEqual("MyColumn2", c2.Name);
Assert.AreEqual(SqlTypes.Int, c2.DataType);
Assert.AreEqual(true, c2.IsNullable);
Assert.AreEqual(null, c2.Length);
Assert.AreEqual(null, c2.Precision);
Assert.AreEqual(null, c2.Scale);
Assert.AreEqual("MyColumn3", c3.Name);
Assert.AreEqual(SqlTypes.VarChar, c3.DataType);
Assert.AreEqual(true, c3.IsNullable);
Assert.AreEqual(32, c3.Length);
Assert.AreEqual(null, c3.Precision);
Assert.AreEqual(null, c3.Scale);
Assert.AreEqual("MyColumn4", c4.Name);
Assert.AreEqual(SqlTypes.Decimal, c4.DataType);
Assert.AreEqual(true, c4.IsNullable);
Assert.AreEqual(null, c4.Length);
Assert.AreEqual(2, c4.Precision);
Assert.AreEqual(10, c4.Scale);
Assert.AreEqual("MyColumn5", c5.Name);
Assert.AreEqual(SqlTypes.NVarChar, c5.DataType);
Assert.AreEqual(true, c5.IsNullable);
Assert.AreEqual(64, c5.Length);
Assert.AreEqual(null, c5.Precision);
Assert.AreEqual(null, c5.Scale);
Assert.AreEqual("MyColumn6", c6.Name);
Assert.AreEqual(SqlTypes.Decimal, c6.DataType);
Assert.AreEqual(true, c6.IsNullable);
Assert.AreEqual(null, c6.Length);
Assert.AreEqual(4, c6.Precision);
Assert.AreEqual(18, c6.Scale);
}
示例6: InitializeTarget
public void InitializeTarget()
{
MigrationContext context = new MigrationContext()
{
SqlProvider = new Sql.SqlServer.SqlServerProvider()
};
Database db = new Database(context);
Table t = db.AddTable("Table");
Target = t.AddColumn("MyColumn", SqlTypes.Int);
}
示例7: DatabaseModel1Test
public void DatabaseModel1Test()
{
Database db = new Database(new MockMigrationContext(Target));
var t = db.AddTable("Customers");
t.AddColumn("CustomerID", SqlTypes.Int).PrimaryKey().AutoIncrement();
t.AddColumn("Firstname", SqlTypes.NVarChar, 32).NotNull();
t.AddColumn("Lastname", SqlTypes.NVarChar, 32).NotNull();
string[] sql = Target.GenerateSqlCommands(db).ToArray();
Assert.AreEqual(1, sql.Length);
Assert.AreEqual("CREATE TABLE [Customers] (" + Environment.NewLine +
"\t[CustomerID] INT NOT NULL IDENTITY(1, 1)," + Environment.NewLine +
"\t[Firstname] NVARCHAR(32) NOT NULL," + Environment.NewLine +
"\t[Lastname] NVARCHAR(32) NOT NULL," + Environment.NewLine +
"\tCONSTRAINT [PK_Customers] PRIMARY KEY ([CustomerID])" + Environment.NewLine +
");", sql[0]);
}
示例8: SetupTables
private static void SetupTables(ListMapping<IDatabase, IMapping> Mappings, IDatabase Key, Database TempDatabase, Graph<IMapping> Structure)
{
Contract.Requires<NullReferenceException>(Mappings != null, "Mappings");
foreach (IMapping Mapping in Mappings[Key].OrderBy(x => x.Order))
{
TempDatabase.AddTable(Mapping.TableName);
SetupProperties(TempDatabase[Mapping.TableName], Mapping);
}
foreach (Vertex<IMapping> Vertex in Structure.Where(x => x.OutgoingEdges.Count > 0))
{
var Mapping = Vertex.Data;
var ForeignMappings = Vertex.OutgoingEdges.Select(x => x.Sink.Data);
foreach (var Property in Mapping.IDProperties)
{
foreach (var ForeignMapping in ForeignMappings)
{
var ForeignProperty = ForeignMapping.IDProperties.FirstOrDefault(x => x.Name == Property.Name);
if (ForeignProperty != null)
{
TempDatabase[Mapping.TableName].AddForeignKey(Property.FieldName, ForeignMapping.TableName, ForeignProperty.FieldName);
}
}
}
}
}