mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Merge pull request #1116 from Kxnrl/fix-insert-identity
修复InsertReturnIdentity由于主键是ushort/short导致的异常
This commit is contained in:
@@ -246,7 +246,6 @@ namespace SqlSugar
|
|||||||
var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey && it.UnderType == UtilConstants.LongType);
|
var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey && it.UnderType == UtilConstants.LongType);
|
||||||
if (snowColumn!=null)
|
if (snowColumn!=null)
|
||||||
{
|
{
|
||||||
;
|
|
||||||
if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0)
|
if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0)
|
||||||
{
|
{
|
||||||
var id = this.ExecuteReturnSnowflakeId();
|
var id = this.ExecuteReturnSnowflakeId();
|
||||||
@@ -277,6 +276,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
setValue = Convert.ToUInt64(idValue);
|
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
|
else
|
||||||
setValue = Convert.ToInt32(idValue);
|
setValue = Convert.ToInt32(idValue);
|
||||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||||
@@ -370,6 +377,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
setValue = Convert.ToUInt64(idValue);
|
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
|
else
|
||||||
setValue = Convert.ToInt32(idValue);
|
setValue = Convert.ToInt32(idValue);
|
||||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||||
|
@@ -246,7 +246,6 @@ namespace SqlSugar
|
|||||||
var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey && it.UnderType == UtilConstants.LongType);
|
var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey && it.UnderType == UtilConstants.LongType);
|
||||||
if (snowColumn!=null)
|
if (snowColumn!=null)
|
||||||
{
|
{
|
||||||
;
|
|
||||||
if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0)
|
if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0)
|
||||||
{
|
{
|
||||||
var id = this.ExecuteReturnSnowflakeId();
|
var id = this.ExecuteReturnSnowflakeId();
|
||||||
@@ -277,6 +276,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
setValue = Convert.ToUInt64(idValue);
|
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
|
else
|
||||||
setValue = Convert.ToInt32(idValue);
|
setValue = Convert.ToInt32(idValue);
|
||||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||||
@@ -370,6 +377,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
setValue = Convert.ToUInt64(idValue);
|
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
|
else
|
||||||
setValue = Convert.ToInt32(idValue);
|
setValue = Convert.ToInt32(idValue);
|
||||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||||
|
Reference in New Issue
Block a user