mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
nullable<enum> insert null
This commit is contained in:
parent
ae11d38ab0
commit
b0c3325314
@ -78,6 +78,7 @@
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\Test01.cs" />
|
||||
<Compile Include="UnitTest\UEnum.cs" />
|
||||
<Compile Include="UnitTest\UInsert.cs" />
|
||||
<Compile Include="UnitTest\UQueryable2.cs" />
|
||||
<Compile Include="UnitTest\UQueue.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
Enum();
|
||||
Tran();
|
||||
Insert();
|
||||
Queue();
|
||||
|
44
Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs
Normal file
44
Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public partial class NewUnitTest
|
||||
{
|
||||
public static void Enum()
|
||||
{
|
||||
Db.CodeFirst.InitTables<Unit00Z11C12>();
|
||||
Db.Insertable(new Unit00Z11C12() { type = UnitType.a, type2 = null }).ExecuteCommand();
|
||||
var x=Db.Queryable<Unit00Z11C12>().Select(it=>new {
|
||||
x=it.type,
|
||||
x2=it.type2
|
||||
}).ToList();
|
||||
|
||||
var x2 = Db.Queryable<Unit00Z11C12>().ToList();
|
||||
Db.Updateable<Unit00Z11C12>().SetColumns(it => it.type2 == UnitType.b)
|
||||
.Where(it=>true).ExecuteCommand();
|
||||
var x3 = Db.Queryable<Unit00Z11C12>().ToList();
|
||||
foreach (var item in x3)
|
||||
{
|
||||
item.type2 = null;
|
||||
}
|
||||
Db.Updateable<Unit00Z11C12>(x3).WhereColumns(it=>it.type).ExecuteCommand();
|
||||
var x4 = Db.Queryable<Unit00Z11C12>().ToList();
|
||||
}
|
||||
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; }
|
||||
}
|
||||
public enum UnitType {
|
||||
a=-1,
|
||||
b=2,
|
||||
c=3
|
||||
}
|
||||
}
|
||||
}
|
@ -475,7 +475,7 @@ namespace SqlSugar
|
||||
{
|
||||
columnInfo.IsArray = true;
|
||||
}
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
if (columnInfo.PropertyType.IsEnum()&& columnInfo.Value!=null)
|
||||
{
|
||||
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ namespace SqlSugar
|
||||
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
|
||||
TableId = i
|
||||
};
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
if (columnInfo.PropertyType.IsEnum()&& columnInfo.Value!=null)
|
||||
{
|
||||
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user