diff --git a/Src/Asp.Net/MySqlTest/MySqlTest.csproj b/Src/Asp.Net/MySqlTest/MySqlTest.csproj index ad70fd8c7..8fec8d5a6 100644 --- a/Src/Asp.Net/MySqlTest/MySqlTest.csproj +++ b/Src/Asp.Net/MySqlTest/MySqlTest.csproj @@ -96,6 +96,7 @@ + diff --git a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs index 2a0a221ed..db78ec7c7 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UnitTestReturnPkList.Init(); UnitSameKeyBug.Init(); UOneManyMany.init(); UDelete.Init(); diff --git a/Src/Asp.Net/MySqlTest/UnitTest/UnitTestReturnPkList.cs b/Src/Asp.Net/MySqlTest/UnitTest/UnitTestReturnPkList.cs new file mode 100644 index 000000000..d5417731d --- /dev/null +++ b/Src/Asp.Net/MySqlTest/UnitTest/UnitTestReturnPkList.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class UnitTestReturnPkList + { + public static void Init() + { + TestIdentity(); + TestLong(); + TestGuid(); + } + + private static void TestGuid() + { + var db = NewUnitTest.Db; + db.CodeFirst.InitTables(); + var ids = db.Insertable(new UnitGuid123() { Name = "a" }).ExecuteReturnPkList(); + if (ids.Count() != 1) { throw new Exception("unit error"); } + if (db.Queryable().In(ids).Count() !=1) { throw new Exception("unit error"); } + var ids2 = db.Insertable(new List() { new UnitGuid123() { Name = "c" }, new UnitGuid123() { Name = "c" } }).ExecuteReturnPkList(); + if (ids2.Count() != 2) { throw new Exception("unit error"); } + if (db.Queryable().In(ids2).Count() != 2) { throw new Exception("unit error"); } + } + + private static void TestLong() + { + var db = NewUnitTest.Db; + db.CodeFirst.InitTables(); + var ids = db.Insertable(new UnitLong1231() { Name = "a" }).ExecuteReturnPkList(); + if (ids.Count(z => z > 0) != 1) { throw new Exception("unit error"); } + var ids2 = db.Insertable(new List() { new UnitLong1231() { Name = "c" }, new UnitLong1231() { Name = "c" } }).ExecuteReturnPkList(); + if (ids2.Count(z => z > 0) != 2) { throw new Exception("unit error"); } + if(db.Queryable().In(ids2).Count()!=2) { throw new Exception("unit error"); } + } + + private static void TestIdentity() + { + var db = NewUnitTest.Db; + db.CodeFirst.InitTables(); + var ids = db.Insertable(new UnitIdentity01() { Name = "a" }).ExecuteReturnPkList(); + if (ids.Count(z => z > 0) != 1) { throw new Exception("unit error"); } + var ids2 = db.Insertable(new List() { new UnitIdentity01() { Name = "c" }, new UnitIdentity01() { Name = "c" } }).ExecuteReturnPkList(); + if (ids2.Count(z => z > 0) != 2) { throw new Exception("unit error"); } + if (db.Queryable().In(ids2).Count() != 2) { throw new Exception("unit error"); } + var list = new List(); + for (int i = 0; i < 1000; i++) + { + list.Add(new UnitIdentity01() { Name = "a" }); + } + var ids3 = db.Insertable(list).ExecuteReturnPkList(); + if (db.Queryable().In(ids3).Count() != 1000) { throw new Exception("unit error"); } + db.DbMaintenance.TruncateTable(); + } + + public class UnitGuid123 + { + [SqlSugar.SugarColumn(IsPrimaryKey = true)] + public Guid id { get; set; } + + public string Name { get; set; } + } + public class UnitLong1231 + { + [SqlSugar.SugarColumn(IsPrimaryKey = true)] + public long id { get; set; } + + public string Name { get; set; } + } + + public class UnitIdentity01 + { + [SqlSugar.SugarColumn(IsIdentity =true,IsPrimaryKey =true)] + public int id { get; set; } + + public string Name { get; set; } + } + } +}