mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
!15 增加 sqlite code first 对多主键建表的支持
Merge pull request !15 from tomato2313/master
This commit is contained in:
commit
e90d428fa6
@ -91,7 +91,7 @@ namespace SqlSugar
|
||||
{
|
||||
var tableName = GetTableName(entityInfo);
|
||||
string backupName=tableName+DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
||||
//Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
||||
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
||||
if (entityInfo.Columns.HasValue())
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE TABLE {0}(\r\n{1} )";
|
||||
return "CREATE TABLE {0}(\r\n{1} $PrimaryKey )";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableColumn
|
||||
@ -234,9 +234,9 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
protected override string CreateIndexSql
|
||||
protected override string CreateIndexSql
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return "CREATE {3} INDEX Index_{0}_{2} ON {0}({1})";
|
||||
}
|
||||
@ -362,7 +362,7 @@ namespace SqlSugar
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override bool BackupTable(string oldTableName, string newTableName, int maxBackupDataRows = int.MaxValue)
|
||||
{
|
||||
@ -390,10 +390,21 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
string sql = GetCreateTableSql(tableName, columns);
|
||||
if (!isCreatePrimaryKey)
|
||||
string primaryKeyInfo = null;
|
||||
|
||||
if (!isCreatePrimaryKey || columns.Count(it => it.IsPrimarykey) > 1)
|
||||
{
|
||||
sql = sql.Replace("PRIMARY KEY AUTOINCREMENT", "").Replace("PRIMARY KEY", "");
|
||||
}
|
||||
|
||||
if (columns.Count(it => it.IsPrimarykey) > 1 && isCreatePrimaryKey)
|
||||
{
|
||||
primaryKeyInfo = string.Format(",\r\n Primary key({0})", string.Join(",", columns.Where(it => it.IsPrimarykey).Select(it => this.SqlBuilder.GetTranslationColumnName(it.DbColumnName))));
|
||||
primaryKeyInfo = primaryKeyInfo.Replace("`", "\"");
|
||||
}
|
||||
|
||||
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
|
||||
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user