From 8fb4b4626531764302ab63558bbfab9f02e6de07 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Wed, 29 Dec 2021 20:36:20 +0800 Subject: [PATCH] Add unit test --- Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs | 55 +++++++++++++++++-- .../InsertableProvider/InsertableProvider.cs | 1 + .../UpdateProvider/UpdateableProvider.cs | 1 + 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs index 9123ae299..978bc7b19 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs @@ -9,25 +9,62 @@ namespace OrmTest public partial class NewUnitTest { public static void Enum() + { + String(); + Int(); + } + private static void String() + { + var db = Db; + + db.CurrentConnectionConfig.MoreSettings = new SqlSugar.ConnMoreSettings + { + TableEnumIsString = true + }; + + db.CodeFirst.InitTables(); + db.Insertable(new Unit00Z1string1() { type = UnitType.a, type2 = null }).ExecuteCommand(); + var x = db.Queryable().Select(it => new + { + x = it.type, + x2 = it.type2 + }).ToList(); + + var x2 = db.Queryable().ToList(); + db.Updateable().SetColumns(it => it.type2 == UnitType.b) + .Where(it => true).ExecuteCommand(); + var x3 = db.Queryable().ToList(); + foreach (var item in x3) + { + item.type2 = null; + } + db.Updateable(x3).WhereColumns(it => it.type).ExecuteCommand(); + var x4 = db.Queryable().ToList(); + + + } + private static void Int() { Db.CodeFirst.InitTables(); Db.Insertable(new Unit00Z11C12() { type = UnitType.a, type2 = null }).ExecuteCommand(); - var x=Db.Queryable().Select(it=>new { - x=it.type, - x2=it.type2 + var x = Db.Queryable().Select(it => new + { + x = it.type, + x2 = it.type2 }).ToList(); var x2 = Db.Queryable().ToList(); Db.Updateable().SetColumns(it => it.type2 == UnitType.b) - .Where(it=>true).ExecuteCommand(); + .Where(it => true).ExecuteCommand(); var x3 = Db.Queryable().ToList(); foreach (var item in x3) { item.type2 = null; } - Db.Updateable(x3).WhereColumns(it=>it.type).ExecuteCommand(); + Db.Updateable(x3).WhereColumns(it => it.type).ExecuteCommand(); var x4 = Db.Queryable().ToList(); } + public class Unit00Z11C12 { [SqlSugar.SugarColumn(ColumnDataType = "int", IsNullable = false)] @@ -35,6 +72,14 @@ namespace OrmTest [SqlSugar.SugarColumn(ColumnDataType ="int",IsNullable =true)] public UnitType? type2 { get; set; } } + + public class Unit00Z1string1 + { + [SqlSugar.SugarColumn(ColumnDataType = "varchar(50)", IsNullable = false)] + public UnitType type { get; set; } + [SqlSugar.SugarColumn(ColumnDataType = "varchar(50)", IsNullable = true)] + public UnitType? type2 { get; set; } + } public enum UnitType { a=-1, b=2, diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 569e2aa1c..992458c57 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -650,6 +650,7 @@ namespace SqlSugar if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true) { columnInfo.Value = columnInfo.Value.ToString(); + columnInfo.PropertyType = UtilConstants.StringType; } else { diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index eda4f5869..58ad0816f 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -574,6 +574,7 @@ namespace SqlSugar { if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true) { + columnInfo.PropertyType = UtilConstants.StringType; columnInfo.Value = columnInfo.Value.ToString(); } else