Update demo

This commit is contained in:
sunkaixuan
2025-09-17 11:15:45 +08:00
parent 540673bfc7
commit 994d517225
2 changed files with 41 additions and 1 deletions

View File

@@ -38,7 +38,7 @@ namespace MongoDbTest
Unitdafasdys.Init();
Enum.Init();
Enum2.Init();
UnitDateTimeFunc.Init();
//主键不是ObjectId类型用例
//The primary key is not an ObjectId type use case
LongPrimaryKey.Init();

View File

@@ -0,0 +1,40 @@
using SqlSugar.MongoDb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MongoDbTest
{
internal class UnitDateTimeFunc
{
public static void Init()
{
var db = DbHelper.GetNewDb();
db.DbMaintenance.TruncateTable<Student>();//清空重置
db.Insertable(new Student() { Name = "error time", Bool = true, CreateDateTime = DateTime.Parse("2025-09-15 00:00:01") }).ExecuteCommand();
db.Insertable(new Student() { Name = "OK time", Bool = true, CreateDateTime = DateTime.Parse("2025-09-16 00:00:01") }).ExecuteCommand();
db.Insertable(new Student() { Name = "error time2", Bool = true, CreateDateTime = DateTime.Parse("2025-09-17 00:00:01") }).ExecuteCommand();
var list1 = db.Queryable<Student>().Where(a => a.CreateDateTime >= DateTime.Parse("2025-09-16 00:00:00") && a.CreateDateTime <= DateTime.Parse("2025-09-16 23:59:59")).ToList();
if (list1.First().Name != "OK time") Cases.ThrowUnitError();
var list2=db.Queryable<Student>().Where(a => DateTime.Parse("2025-09-16 00:00:00")<=a.CreateDateTime && a.CreateDateTime <= DateTime.Parse("2025-09-16 23:59:59")).ToList();
if (list2.First().Name!= "OK time") Cases.ThrowUnitError();
}
[SqlSugar.SugarTable("UnitStudent1ssss23s131")]
public class Student : MongoDbBase
{
public string Name { get; set; }
public bool Bool { get; set; }
public bool? BoolNull { get; set; }
public int SchoolId { get; set; }
public int? SchoolIdNull { get; set; }
public DateTime CreateDateTime { get; set; }
}
}
}