diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs index 61f967d2c..c4cd68c62 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs +++ b/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 columns = new List(); if (entityInfo.Columns.HasValue()) { diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs index a2bedef61..354a08da0 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs +++ b/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; }