Add unit test

This commit is contained in:
sunkaixuna 2021-12-29 20:36:20 +08:00
parent 2792ebfbe6
commit 8fb4b46265
3 changed files with 52 additions and 5 deletions

View File

@ -9,25 +9,62 @@ namespace OrmTest
public partial class NewUnitTest public partial class NewUnitTest
{ {
public static void Enum() public static void Enum()
{
String();
Int();
}
private static void String()
{
var db = Db;
db.CurrentConnectionConfig.MoreSettings = new SqlSugar.ConnMoreSettings
{
TableEnumIsString = true
};
db.CodeFirst.InitTables<Unit00Z1string1>();
db.Insertable(new Unit00Z1string1() { type = UnitType.a, type2 = null }).ExecuteCommand();
var x = db.Queryable<Unit00Z1string1>().Select(it => new
{
x = it.type,
x2 = it.type2
}).ToList();
var x2 = db.Queryable<Unit00Z1string1>().ToList();
db.Updateable<Unit00Z1string1>().SetColumns(it => it.type2 == UnitType.b)
.Where(it => true).ExecuteCommand();
var x3 = db.Queryable<Unit00Z1string1>().ToList();
foreach (var item in x3)
{
item.type2 = null;
}
db.Updateable<Unit00Z1string1>(x3).WhereColumns(it => it.type).ExecuteCommand();
var x4 = db.Queryable<Unit00Z1string1>().ToList();
}
private static void Int()
{ {
Db.CodeFirst.InitTables<Unit00Z11C12>(); Db.CodeFirst.InitTables<Unit00Z11C12>();
Db.Insertable(new Unit00Z11C12() { type = UnitType.a, type2 = null }).ExecuteCommand(); Db.Insertable(new Unit00Z11C12() { type = UnitType.a, type2 = null }).ExecuteCommand();
var x=Db.Queryable<Unit00Z11C12>().Select(it=>new { var x = Db.Queryable<Unit00Z11C12>().Select(it => new
x=it.type, {
x2=it.type2 x = it.type,
x2 = it.type2
}).ToList(); }).ToList();
var x2 = Db.Queryable<Unit00Z11C12>().ToList(); var x2 = Db.Queryable<Unit00Z11C12>().ToList();
Db.Updateable<Unit00Z11C12>().SetColumns(it => it.type2 == UnitType.b) Db.Updateable<Unit00Z11C12>().SetColumns(it => it.type2 == UnitType.b)
.Where(it=>true).ExecuteCommand(); .Where(it => true).ExecuteCommand();
var x3 = Db.Queryable<Unit00Z11C12>().ToList(); var x3 = Db.Queryable<Unit00Z11C12>().ToList();
foreach (var item in x3) foreach (var item in x3)
{ {
item.type2 = null; item.type2 = null;
} }
Db.Updateable<Unit00Z11C12>(x3).WhereColumns(it=>it.type).ExecuteCommand(); Db.Updateable<Unit00Z11C12>(x3).WhereColumns(it => it.type).ExecuteCommand();
var x4 = Db.Queryable<Unit00Z11C12>().ToList(); var x4 = Db.Queryable<Unit00Z11C12>().ToList();
} }
public class Unit00Z11C12 public class Unit00Z11C12
{ {
[SqlSugar.SugarColumn(ColumnDataType = "int", IsNullable = false)] [SqlSugar.SugarColumn(ColumnDataType = "int", IsNullable = false)]
@ -35,6 +72,14 @@ namespace OrmTest
[SqlSugar.SugarColumn(ColumnDataType ="int",IsNullable =true)] [SqlSugar.SugarColumn(ColumnDataType ="int",IsNullable =true)]
public UnitType? type2 { get; set; } 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 { public enum UnitType {
a=-1, a=-1,
b=2, b=2,

View File

@ -650,6 +650,7 @@ namespace SqlSugar
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true) if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{ {
columnInfo.Value = columnInfo.Value.ToString(); columnInfo.Value = columnInfo.Value.ToString();
columnInfo.PropertyType = UtilConstants.StringType;
} }
else else
{ {

View File

@ -574,6 +574,7 @@ namespace SqlSugar
{ {
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true) if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{ {
columnInfo.PropertyType = UtilConstants.StringType;
columnInfo.Value = columnInfo.Value.ToString(); columnInfo.Value = columnInfo.Value.ToString();
} }
else else