This commit is contained in:
sunkaixuan 2025-08-04 19:33:38 +08:00
parent 6f95a155ee
commit 78c2f1840d
2 changed files with 55 additions and 0 deletions

View File

@ -16,6 +16,7 @@ namespace MongoDbTest
QuerySelect.Init();
QuerySelect2.Init();
QueryJson.Init();
QueryJson2.Init();
QueryLeftJoin.Init();
QueryLeftJoin2.Init();
QueryLeftJoin3.Init();

View File

@ -0,0 +1,54 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SqlSugar.MongoDb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MongoDbTest
{
public class QueryJson2
{
internal static void Init()
{
var db = DbHelper.GetNewDb();
db.CodeFirst.InitTables<Student>();
db.DbMaintenance.TruncateTable<Student>();
db.Insertable(new Student()
{
Age = 1,
Book = new Book() { SchoolId = ObjectId.GenerateNewId().ToString() }
}).ExecuteCommand();
var data = db.Queryable<Student>().First();
var list=db.Queryable<Student>().Where(s => s.Book.SchoolId == data.Book.SchoolId).ToList();
if (list.Any() == false) Cases.ThrowUnitError();
}
[SqlSugar.SugarTable("UnitStudentdddd1")]
public class Student : MongoDbBase
{
public string Name { get; set; }
public string SchoolId { get; set; }
public int Age { get; set; }
public DateTime CreateDateTime { get; set; }
[SqlSugar.SugarColumn(IsJson = true)]
public Book Book { get; set; }
}
public class Book
{
[BsonRepresentation(BsonType.ObjectId)]//比普通类多个序列化ObjectId
[SqlSugar.SugarColumn(ColumnDataType = nameof(ObjectId))]
public string SchoolId { get; set; }
public decimal BookId { get; set; }
}
}
}