本文整理汇总了C#中TableSchema.KeyPrimary方法的典型用法代码示例。如果您正苦于以下问题:C# TableSchema.KeyPrimary方法的具体用法?C# TableSchema.KeyPrimary怎么用?C# TableSchema.KeyPrimary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableSchema
的用法示例。
在下文中一共展示了TableSchema.KeyPrimary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeDdlTableCreate
protected override string MakeDdlTableCreate(TableSchema table, bool withConstraint)
{
// На параметр 'withConstraint' приходится забить, т.к. AUTOINCREMENT
// может быть задан только "по месту".
// Лишние ALTER TABLE потом тупо удаляются в AfterSchemaComparision.
var stat = new StringBuilder();
var pk = table.KeyPrimary();
foreach (var column in table.Columns)
{
if (stat.Length > 0)
stat.Append(",\n\t");
stat.Append(ParseColumn(column));
if (column.AutoIncrement)
{
if (column.Seed != 1)
throw new NotSupportedException(
@"SQLite does not support auto increment columns with the seed other then 1");
if (column.Increment != 1)
throw new NotSupportedException(
@"SQLite does not support auto increment columns with the increment other then 1");
if (pk == null || pk.Columns != column.Name || column.Type != ColumnType.Integer)
throw new NotSupportedException(
@"SQLite supports only autoincrement for integer primary keys");
stat.Append(@" PRIMARY KEY AUTOINCREMENT");
pk = null;
}
}
foreach (var key in table.Keys)
{
if (key.KeyType == ConstraintType.KeyPrimary && pk == null)
// Primary key was already processed by an autoincrement column.
//
continue;
if (stat.Length > 0)
stat.Append(",\n\t");
stat.Append(ParseKey(key));
}
return string.Format(@"CREATE TABLE {0} ({1})", MakeDdlElementName(table.Name), stat);
}