Browse Source

Update sqlite

pull/16/MERGE
sunkaixuan 3 years ago
parent
commit
88e74cdd0d
  1. 2
      Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs
  2. 13
      Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs

2
Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs

@ -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())
{

13
Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs

@ -358,10 +358,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…
Cancel
Save