SqlSugar/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs

172 lines
6.2 KiB
C#
Raw Normal View History

2023-04-06 12:27:58 +08:00
using SqlSugar;
using SqlSugar.DbConvert;
2023-04-03 13:57:17 +08:00
using System;
2021-01-27 03:49:53 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
2023-04-13 22:24:05 +08:00
public UnitType xxx { get; set; }
2021-01-27 03:49:53 +08:00
public static void Enum()
2021-12-29 20:36:20 +08:00
{
2023-04-13 22:24:05 +08:00
String(new NewUnitTest() { xxx = UnitType.a });
2021-12-29 20:36:20 +08:00
Int();
}
2023-04-13 22:24:05 +08:00
private static void String(NewUnitTest x)
2021-12-29 20:36:20 +08:00
{
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();
2021-12-30 16:42:55 +08:00
List<UnitType> ids = new List<UnitType>() {
UnitType.a,
UnitType.b
};
2022-08-31 19:23:55 +08:00
var zz = UnitType.b;
2023-04-13 22:24:05 +08:00
var x1 = db.Queryable<Unit00Z1string1>()
2022-08-31 19:23:55 +08:00
.Where(it => it.type == zz)
2021-12-30 16:42:55 +08:00
.Where(it=>it.type2== UnitType.b)
.Where(it=> ids.Contains(it.type)).Select(it => new
2021-12-29 20:36:20 +08:00
{
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();
2022-01-05 20:39:15 +08:00
db.Updateable<Unit00Z1string1>().SetColumns(it => new Unit00Z1string1 {
type=UnitType.a,
type2 = UnitType.b
})
.Where(it => true).ExecuteCommand();
2022-03-13 11:42:11 +08:00
db.Queryable<Unit00Z1string1>().WhereClass(new Unit00Z1string1()
{
type = UnitType.a,
type2 = UnitType.b
}).ToList();
2023-04-03 13:57:17 +08:00
var type = UnitType.a;
var p2=db.Updateable<Unit00Z1string1>().SetColumns(it => new Unit00Z1string1
{
type = type,
type2 = type
})
.Where(it => true).ToSql();
if (!(p2.Value.First().Value is string))
2023-04-13 22:24:05 +08:00
{
throw new Exception("unit error");
}
p2 = db.Updateable<Unit00Z1string1>().SetColumns(it => new Unit00Z1string1
{
type = x.xxx,
type2 = type
})
.Where(it => true).ToSql();
if (!(p2.Value.First().Value is string))
2023-04-03 13:57:17 +08:00
{
throw new Exception("unit error");
}
db.CurrentConnectionConfig.MoreSettings.TableEnumIsString = false;
var p=db.Updateable<Unit00Z1String1>().SetColumns(it => new Unit00Z1String1
{
type = type,
type2 = type
})
.Where(it => true).ToSql();
if (!(p.Value.First().Value is string))
{
throw new Exception("unit error");
}
2023-04-06 12:27:58 +08:00
var type3 = UnitType.a;
var list=db.Queryable<Unit00Z1String1>().Where(it => it.type == type).ToList();
var list2 = db.Queryable<Unit00Z1String1>().Where(it => it.type == UnitType.a).ToList();
2023-04-13 22:24:05 +08:00
var list21 = db.Queryable<Unit00Z1String1>().Where(it => it.type == x.xxx).ToList();
2023-04-21 09:25:08 +08:00
List<UnitType> unitTypes = new List<UnitType>()
{
UnitType.a
};
List<UnitType?> unitTypes2 = new List<UnitType?>()
{
UnitType.a
};
Db.Queryable<Unit00Z1String1>()
.Where(it=>""==type3.ToString())
.Where(it => unitTypes2.Contains(it.type2))
.Where(it => unitTypes.Contains(it.type)).ToList();
2021-12-29 20:36:20 +08:00
}
private static void Int()
2021-01-27 03:49:53 +08:00
{
Db.CodeFirst.InitTables<Unit00Z11C12>();
Db.Insertable(new Unit00Z11C12() { type = UnitType.a, type2 = null }).ExecuteCommand();
2021-12-29 20:36:20 +08:00
var x = Db.Queryable<Unit00Z11C12>().Select(it => new
{
x = it.type,
x2 = it.type2
2021-01-27 03:49:53 +08:00
}).ToList();
var x2 = Db.Queryable<Unit00Z11C12>().ToList();
Db.Updateable<Unit00Z11C12>().SetColumns(it => it.type2 == UnitType.b)
2021-12-29 20:36:20 +08:00
.Where(it => true).ExecuteCommand();
2021-01-27 03:49:53 +08:00
var x3 = Db.Queryable<Unit00Z11C12>().ToList();
foreach (var item in x3)
{
item.type2 = null;
}
2021-12-29 20:36:20 +08:00
Db.Updateable<Unit00Z11C12>(x3).WhereColumns(it => it.type).ExecuteCommand();
2021-01-27 03:49:53 +08:00
var x4 = Db.Queryable<Unit00Z11C12>().ToList();
2022-03-13 11:42:11 +08:00
Db.Queryable<Unit00Z11C12>().WhereClass(new Unit00Z11C12() {
type= UnitType.a,
type2=UnitType.b
}).ToList();
2021-01-27 03:49:53 +08:00
}
2021-12-29 20:36:20 +08:00
2021-01-27 03:49:53 +08:00
public class Unit00Z11C12
{
[SqlSugar.SugarColumn(ColumnDataType = "int", IsNullable = false)]
public UnitType type { get; set; }
[SqlSugar.SugarColumn(ColumnDataType ="int",IsNullable =true)]
public UnitType? type2 { get; set; }
}
2023-04-03 13:57:17 +08:00
public class Unit00Z1String1
{
[SqlSugar.SugarColumn(ColumnDataType = "varchar(50)", IsNullable = false, SqlParameterDbType = typeof(EnumToStringConvert))]
public UnitType type { get; set; }
[SqlSugar.SugarColumn(ColumnDataType = "varchar(50)", IsNullable = true, SqlParameterDbType = typeof(EnumToStringConvert))]
public UnitType? type2 { get; set; }
}
2021-12-29 20:36:20 +08:00
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; }
}
2021-01-27 03:49:53 +08:00
public enum UnitType {
a=-1,
b=2,
c=3
}
}
}