mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
Update demo
This commit is contained in:
@@ -1,58 +1,44 @@
|
||||
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;
|
||||
|
||||
|
||||
using SqlSugar;
|
||||
namespace MongoDbTest
|
||||
{
|
||||
public class QueryJson4
|
||||
public class QueryJson3
|
||||
{
|
||||
internal static void Init()
|
||||
public static void Init()
|
||||
{
|
||||
var db = DbHelper.GetNewDb();
|
||||
db.CodeFirst.InitTables<Student>();
|
||||
db.DbMaintenance.TruncateTable<Student>();
|
||||
var dt = DateTime.Now;
|
||||
db.Insertable(new Student()
|
||||
{
|
||||
Age = 1,
|
||||
Book = new Book()
|
||||
{
|
||||
SchoolId = 1,
|
||||
Book2 = new Book() { SchoolId=1,Book2 = new Book() { SchoolId = 2 } }
|
||||
}
|
||||
}).ExecuteCommand();
|
||||
var data1 = db.Queryable<Student>().Where(s=>s.Book.Book2.SchoolId==1).ToList();
|
||||
var data2 = db.Queryable<Student>().Where(s => s.Book.Book2.Book2.SchoolId == 2).ToList();
|
||||
|
||||
}
|
||||
|
||||
[SqlSugar.SugarTable("UnitStudentd23351")]
|
||||
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
|
||||
{
|
||||
public int SchoolId { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsJson = true)]
|
||||
public Book Book2 { get; set; }
|
||||
var db = DbHelper.GetNewDb();
|
||||
db.DbMaintenance.TruncateTable<NoticeEntity>();
|
||||
db.Insertable<NoticeEntity>(new NoticeEntity() { Id = 12312312L, NoticeTitle = "88888", noticeContentInfos = new List<NoticeContentInfo>() { new NoticeContentInfo { SubjectId = 1 } } }).ExecuteCommand();
|
||||
var da = db.Updateable<NoticeEntity>()
|
||||
.SetColumns(it => new NoticeEntity { NoticeTitle = "66666" }, true).Where(it => it.Id == 12312312L)
|
||||
.ExecuteCommand() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 通知公告
|
||||
/// </summary>
|
||||
[SugarTable("NoticeInfoComponent")]
|
||||
public class NoticeEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "_id")]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 通知公告标题
|
||||
/// </summary>
|
||||
public string NoticeTitle { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 通知公告内容
|
||||
/// </summary>
|
||||
[SugarColumn(IsJson = true)]
|
||||
public List<NoticeContentInfo> noticeContentInfos { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class NoticeContentInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 模块
|
||||
/// </summary>
|
||||
public int SubjectId { get; set; }
|
||||
}
|
||||
|
58
Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryJson4.cs
Normal file
58
Src/Asp.NetCore2/MongoDbTest/UnitTest/QueryJson4.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
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 QueryJson4
|
||||
{
|
||||
internal static void Init()
|
||||
{
|
||||
var db = DbHelper.GetNewDb();
|
||||
db.CodeFirst.InitTables<Student>();
|
||||
db.DbMaintenance.TruncateTable<Student>();
|
||||
var dt = DateTime.Now;
|
||||
db.Insertable(new Student()
|
||||
{
|
||||
Age = 1,
|
||||
Book = new Book()
|
||||
{
|
||||
SchoolId = 1,
|
||||
Book2 = new Book() { SchoolId=1,Book2 = new Book() { SchoolId = 2 } }
|
||||
}
|
||||
}).ExecuteCommand();
|
||||
var data1 = db.Queryable<Student>().Where(s=>s.Book.Book2.SchoolId==1).ToList();
|
||||
var data2 = db.Queryable<Student>().Where(s => s.Book.Book2.Book2.SchoolId == 2).ToList();
|
||||
|
||||
}
|
||||
|
||||
[SqlSugar.SugarTable("UnitStudentd23351")]
|
||||
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
|
||||
{
|
||||
public int SchoolId { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsJson = true)]
|
||||
public Book Book2 { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
|
||||
using SqlSugar;
|
||||
namespace MongoDbTest
|
||||
{
|
||||
public class QueryJson3
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = DbHelper.GetNewDb();
|
||||
db.DbMaintenance.TruncateTable<NoticeEntity>();
|
||||
db.Insertable<NoticeEntity>(new NoticeEntity() { Id = 12312312L, NoticeTitle = "88888", noticeContentInfos = new List<NoticeContentInfo>() { new NoticeContentInfo { SubjectId = 1 } } }).ExecuteCommand();
|
||||
var da = db.Updateable<NoticeEntity>()
|
||||
.SetColumns(it => new NoticeEntity { NoticeTitle = "66666" }, true).Where(it => it.Id == 12312312L)
|
||||
.ExecuteCommand() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 通知公告
|
||||
/// </summary>
|
||||
[SugarTable("NoticeInfoComponent")]
|
||||
public class NoticeEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "_id")]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 通知公告标题
|
||||
/// </summary>
|
||||
public string NoticeTitle { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 通知公告内容
|
||||
/// </summary>
|
||||
[SugarColumn(IsJson = true)]
|
||||
public List<NoticeContentInfo> noticeContentInfos { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class NoticeContentInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 模块
|
||||
/// </summary>
|
||||
public int SubjectId { get; set; }
|
||||
}
|
Reference in New Issue
Block a user