diff --git a/SqlServerTest/UnitTest/DataTest.cs b/SqlServerTest/UnitTest/DataTest.cs index a27868484..7b82bfb38 100644 --- a/SqlServerTest/UnitTest/DataTest.cs +++ b/SqlServerTest/UnitTest/DataTest.cs @@ -41,6 +41,7 @@ namespace OrmTest.UnitTest }; var id = db.Insertable(insertObject).ExecuteReutrnIdentity(); var data = db.Queryable().InSingle(id); + db.Updateable(data).ExecuteCommand(); } public SqlSugarClient GetInstance() { diff --git a/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 486b0177a..fe6c2e7b5 100644 --- a/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -132,7 +132,7 @@ namespace SqlSugar foreach (var item in this.InsertBuilder.DbColumnInfoList) { if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List(); - var paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value); + var paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value,item.PropertyType); if (InsertBuilder.IsInsertNull && paramters.Value == null) { continue; } @@ -155,6 +155,7 @@ namespace SqlSugar Value = column.PropertyInfo.GetValue(item,null), DbColumnName = GetDbColumnName(column.PropertyName), PropertyName = column.PropertyName, + PropertyType=PubMethod.GetUnderType(column.PropertyInfo), TableId = i }; insertItem.Add(columnInfo); diff --git a/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 7fd2a8479..460c0ccfc 100644 --- a/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -145,6 +145,7 @@ namespace SqlSugar Value = column.PropertyInfo.GetValue(item, null), DbColumnName = GetDbColumnName(column.PropertyName), PropertyName = column.PropertyName, + PropertyType=PubMethod.GetUnderType(column.PropertyInfo), TableId = i }; insertItem.Add(columnInfo); @@ -171,7 +172,7 @@ namespace SqlSugar foreach (var item in this.UpdateBuilder.DbColumnInfoList) { if (this.UpdateBuilder.Parameters == null) this.UpdateBuilder.Parameters = new List(); - this.UpdateBuilder.Parameters.Add(new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value)); + this.UpdateBuilder.Parameters.Add(new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value,item.PropertyType)); } } diff --git a/SqlSugar/Common/PubConst.cs b/SqlSugar/Common/PubConst.cs index e51b53145..3980de698 100644 --- a/SqlSugar/Common/PubConst.cs +++ b/SqlSugar/Common/PubConst.cs @@ -14,6 +14,7 @@ namespace SqlSugar internal static Type GuidType = typeof(Guid); internal static Type DateType = typeof(DateTime); internal static Type ByteType = typeof(Byte); + internal static Type ByteArrayType = typeof(byte[]); internal static Type BoolType = typeof(bool); internal static Type ObjType = typeof(object); internal static Type Dob = typeof(double); diff --git a/SqlSugar/Common/PubMethod.cs b/SqlSugar/Common/PubMethod.cs index 82aba0b72..6763fa422 100644 --- a/SqlSugar/Common/PubMethod.cs +++ b/SqlSugar/Common/PubMethod.cs @@ -17,6 +17,13 @@ namespace SqlSugar return unType; } + internal static Type GetUnderType(PropertyInfo propertyInfo) + { + Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); + unType = unType ?? propertyInfo.PropertyType; + return unType; + } + internal static T IsNullReturnNew(T returnObj) where T : new() { if (returnObj.IsNullOrEmpty()) diff --git a/SqlSugar/Entities/DbColumnInfo.cs b/SqlSugar/Entities/DbColumnInfo.cs index 54ade95b9..e9f81858a 100644 --- a/SqlSugar/Entities/DbColumnInfo.cs +++ b/SqlSugar/Entities/DbColumnInfo.cs @@ -11,6 +11,7 @@ namespace SqlSugar public string DbColumnName { get; set; } public string PropertyName { get; set; } public string DataType { get; set; } + public Type PropertyType { get; set; } public int Length { get; set; } public string ColumnDescription { get; set; } public string DefaultValue { get; set; } diff --git a/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs b/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs index 751cf6581..da100eaa3 100644 --- a/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs +++ b/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs @@ -14,11 +14,33 @@ namespace SqlSugar this.Value = value; this.ParameterName = name; } - public SugarParameter(string name, object value,bool isOutput) + public SugarParameter(string name, object value, Type type) { this.Value = value; this.ParameterName = name; - if (isOutput) { + if (type == PubConst.ByteArrayType) + { + this.DbType = System.Data.DbType.Binary; + } + else if (type == PubConst.GuidType) + { + this.DbType = System.Data.DbType.Guid; + } + else if (type == PubConst.IntType) + { + this.DbType = System.Data.DbType.Int32; + } + else if (type == PubConst.DateType) + { + this.DbType = System.Data.DbType.Date; + } + } + public SugarParameter(string name, object value, bool isOutput) + { + this.Value = value; + this.ParameterName = name; + if (isOutput) + { this.Direction = ParameterDirection.Output; } } @@ -74,7 +96,7 @@ namespace SqlSugar public override DataRowVersion SourceVersion { - get;set; + get; set; } public override void ResetDbType()