From fd347a1113c626c2185d42cdeb6a71e5d5f4a36d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 14 Apr 2023 19:03:17 +0800 Subject: [PATCH] Synchronization code --- .../SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 4a718b03e..cece980da 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -443,6 +443,11 @@ namespace SqlSugar ChangeKey(entityInfo, tableName, item); } } + if (entityColumns.Count(it => it.IsPrimarykey)==1&&dbColumns.Count(it => it.IsPrimarykey) ==0) + { + var addPk=entityColumns.First(it => it.IsPrimarykey); + this.Context.DbMaintenance.AddPrimaryKey(tableName, addPk.DbColumnName); + } if (isMultiplePrimaryKey) { var oldPkNames = dbColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it => it).ToList();