From d923e78006eed3058a07e0b2f419716cb2b6f7fe Mon Sep 17 00:00:00 2001 From: Kyle Date: Wed, 28 Dec 2022 23:02:42 +0800 Subject: [PATCH] Fix InsertReturnIdentity if column is short/ushort --- .../InsertableProvider/InsertableProvider.cs | 17 ++++++++++++++++- .../InsertableProvider/InsertableProvider.cs | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index dbb005e7b..64646d3ce 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -246,7 +246,6 @@ namespace SqlSugar var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey && it.UnderType == UtilConstants.LongType); if (snowColumn!=null) { - ; if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0) { var id = this.ExecuteReturnSnowflakeId(); @@ -277,6 +276,14 @@ namespace SqlSugar { setValue = Convert.ToUInt64(idValue); } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ushort))) + { + setValue = Convert.ToUInt16(idValue); + } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(short))) + { + setValue = Convert.ToInt16(idValue); + } else setValue = Convert.ToInt32(idValue); this.Context.EntityMaintenance.GetProperty(identityKey).SetValue(result, setValue, null); @@ -370,6 +377,14 @@ namespace SqlSugar { setValue = Convert.ToUInt64(idValue); } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ushort))) + { + setValue = Convert.ToUInt16(idValue); + } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(short))) + { + setValue = Convert.ToInt16(idValue); + } else setValue = Convert.ToInt32(idValue); this.Context.EntityMaintenance.GetProperty(identityKey).SetValue(result, setValue, null); diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index dbb005e7b..64646d3ce 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -246,7 +246,6 @@ namespace SqlSugar var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey && it.UnderType == UtilConstants.LongType); if (snowColumn!=null) { - ; if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0) { var id = this.ExecuteReturnSnowflakeId(); @@ -277,6 +276,14 @@ namespace SqlSugar { setValue = Convert.ToUInt64(idValue); } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ushort))) + { + setValue = Convert.ToUInt16(idValue); + } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(short))) + { + setValue = Convert.ToInt16(idValue); + } else setValue = Convert.ToInt32(idValue); this.Context.EntityMaintenance.GetProperty(identityKey).SetValue(result, setValue, null); @@ -370,6 +377,14 @@ namespace SqlSugar { setValue = Convert.ToUInt64(idValue); } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ushort))) + { + setValue = Convert.ToUInt16(idValue); + } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(short))) + { + setValue = Convert.ToInt16(idValue); + } else setValue = Convert.ToInt32(idValue); this.Context.EntityMaintenance.GetProperty(identityKey).SetValue(result, setValue, null);