mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-20 00:44:19 +08:00
Add demo
This commit is contained in:
parent
6f95a155ee
commit
78c2f1840d
@ -16,6 +16,7 @@ namespace MongoDbTest
|
||||
QuerySelect.Init();
|
||||
QuerySelect2.Init();
|
||||
QueryJson.Init();
|
||||
QueryJson2.Init();
|
||||
QueryLeftJoin.Init();
|
||||
QueryLeftJoin2.Init();
|
||||
QueryLeftJoin3.Init();
|
||||
|
54
Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryJson2.cs
Normal file
54
Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryJson2.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user