本文整理汇总了C#中IEntityType.IsPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:C# IEntityType.IsPrimaryKey方法的具体用法?C# IEntityType.IsPrimaryKey怎么用?C# IEntityType.IsPrimaryKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntityType
的用法示例。
在下文中一共展示了IEntityType.IsPrimaryKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTable
private void CreateTable(IEntityType type)
{
String tableName = type.TableName;
String columns = "";
String columnsOnly = "";
var indexedFields = new List<string>();
foreach (string column in type.GetColumns())
{
Type columnType = GetType(type.GetPropertyType(column));
if (!_supportedTypes.ContainsKey(columnType))
throw new Exception(String.Format("Unsupported column type '{0}'", columnType));
String columnName = String.Format("{0}", column);
String typeDeclaration = String.Format(_supportedTypes[columnType].TypeName);
String primaryKey = type.IsPrimaryKey(column) ? "PRIMARY KEY" : "";
const string notNull = "";
if (type.IsIndexed(column))
indexedFields.Add(columnName);
String s = String.Format("[{0}] {1} {2} {3}", columnName, typeDeclaration, notNull, primaryKey);
String s1 = String.Format("[{0}]", columnName);
if (!String.IsNullOrEmpty(columns))
{
s = "," + s;
s1 = "," + s1;
}
columns = columns + s;
columnsOnly = columnsOnly + s1;
}
columns += ",[IsTombstone] INTEGER,[IsDirty] INTEGER";
columnsOnly += ",[IsDirty]";
//create table
using (var cmd = new SqliteCommand(String.Format("CREATE TABLE [_{0}] ({1})", tableName, columns), ActiveConnection))
cmd.ExecuteNonQuery();
//create tran table
using (var cmd = new SqliteCommand(String.Format("CREATE TABLE [__{0}] ({1})", tableName, columns), ActiveConnection))
cmd.ExecuteNonQuery();
//create indexes
indexedFields.Add("IsTombstone");
foreach (String idx in indexedFields)
{
String idxScript = String.Format("CREATE INDEX [{0}_{1}] ON _{0}([{1}])", tableName, idx);
using (var idxCmd = new SqliteCommand(idxScript, ActiveConnection))
idxCmd.ExecuteNonQuery();
}
//create view
using (var cmd = new SqliteCommand(String.Format(
"CREATE VIEW [{0}] AS SELECT {1} FROM [_{0}] WHERE IsTombstone = 0", tableName, columnsOnly), ActiveConnection))
cmd.ExecuteNonQuery();
}