diff --git a/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs index 1213f4394..cc910e254 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs @@ -43,9 +43,18 @@ namespace OrmTest Db.Insertable(new List { new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand(); var list2 = Db.Queryable().ToList(); Db.Insertable(new UnitDateOfTime222() { DateTimeOffset1 = null }).ExecuteCommand(); - + if(Db.DbMaintenance.IsAnyTable("Unit1afa113111")) + Db.DbMaintenance.DropTable("Unit1afa113111"); + Db.CodeFirst.InitTables(); + var entity=Db.Insertable(new Unit1afa113111() { Name = "a" }).ExecuteReturnEntity(); } + public class Unit1afa113111 + { + [SugarColumn(ColumnName ="aid",IsPrimaryKey =true,IsIdentity =true,ColumnDataType ="int(11)unsigned")] + public uint id { get; set; } + public string Name { get; set; } + } public class UnitDateOfTime2 { [SqlSugar.SugarColumn(ColumnDataType ="datetime(3)")] diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 2547d4300..118c7283f 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -203,6 +203,14 @@ namespace SqlSugar object setValue = 0; if (idValue > int.MaxValue) setValue = idValue; + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(uint))) + { + setValue = Convert.ToUInt32(idValue); + } + else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ulong))) + { + setValue = Convert.ToUInt64(idValue); + } else setValue = Convert.ToInt32(idValue); this.Context.EntityMaintenance.GetProperty(identityKey).SetValue(result, setValue, null);