Update mongodb

This commit is contained in:
sunkaixuan
2025-06-12 17:51:23 +08:00
parent 4906faa2c3
commit f5b0319b5d
3 changed files with 38 additions and 2 deletions

View File

@@ -11,7 +11,8 @@ namespace MongoDbTest
{ {
public static void Init() public static void Init()
{ {
SingleQuery.Init(); QuerySingle.Init();
QueryWhere.Init();
} }
public static void ThrowUnitError() public static void ThrowUnitError()
{ {

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace MongoDbTest namespace MongoDbTest
{ {
public class SingleQuery public class QuerySingle
{ {
public static void Init() public static void Init()
{ {

View File

@@ -0,0 +1,35 @@
using SqlSugar.MongoDb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MongoDbTest
{
public class QueryWhere
{
public static void Init()
{
var db = DBHelper.DbHelper.GetNewDb();
db.CodeFirst.InitTables<Student>();
db.DbMaintenance.TruncateTable<Student>();
db.Insertable(new Student() { Name = "jack",Bool=true, SchoolId =2 }).ExecuteCommand();
db.Insertable(new Student() { Name = "tom_null", Bool = false,BoolNull=true, SchoolId =3 ,SchoolIdNull=4}).ExecuteCommand();
var list=db.Queryable<Student>().ToList();
if (list.First() is { } first && (first.BoolNull != null || first.SchoolIdNull != null)) Cases.ThrowUnitError();
if (list.Last() is { } last && (last.BoolNull != true || last.SchoolIdNull != 4)) 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; }
}
}
}