Fix InsertReturnIdentity if column is short/ushort

This commit is contained in:
Kyle
2022-12-28 23:02:42 +08:00
parent 3b56a4e78a
commit d923e78006
2 changed files with 32 additions and 2 deletions

View File

@@ -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<T>(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<T>(identityKey).SetValue(result, setValue, null);

View File

@@ -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<T>(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<T>(identityKey).SetValue(result, setValue, null);