mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using SqlSugar.MongoDb;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MongoDbTest
|
|
{
|
|
public class Update
|
|
{
|
|
internal static void Init()
|
|
{
|
|
var db = DBHelper.DbHelper.GetNewDb();
|
|
db.CodeFirst.InitTables<Student>();
|
|
db.DbMaintenance.TruncateTable<Student>();
|
|
db.Insertable(new Student() { Age = 1, Name = "11", SchoolId = "111", CreateDateTime = DateTime.Now }).ExecuteCommandAsync().GetAwaiter().GetResult();
|
|
db.Insertable(new List<Student>() {
|
|
new Student() { Age = 2, Name = "22", SchoolId = "222", CreateDateTime = DateTime.Now },
|
|
new Student() { Age = 3, Name = "33", SchoolId = "333", CreateDateTime = DateTime.Now }
|
|
}).ExecuteCommandAsync().GetAwaiter().GetResult();
|
|
|
|
var list=db.Queryable<Student>().ToList();
|
|
db.Insertable(new Student() { Age = 1, Name = "xx", SchoolId = "111", CreateDateTime = DateTime.Now }).ExecuteCommandAsync().GetAwaiter().GetResult();
|
|
foreach (var item in list)
|
|
{
|
|
item.Name = item.Name + "haha";
|
|
}
|
|
db.Updateable(list).ExecuteCommand();
|
|
var list2 = db.Queryable<Student>().ToList();
|
|
foreach (var item in list2)
|
|
{
|
|
if (item.Name == "xx") continue;
|
|
if (!item.Name.EndsWith("haha")) Cases.ThrowUnitError();
|
|
}
|
|
db.Updateable<Student>()
|
|
.SetColumns(it => new Student() { Name = "yy" }).Where(it => it.Name == "xx").ExecuteCommand();
|
|
|
|
var datas= db.Queryable<Student>().Where(it => it.Id == list2.Last().Id).ToList();
|
|
if(datas.Count!=1|| datas.First().Name!="yy") Cases.ThrowUnitError();
|
|
}
|
|
[SqlSugar.SugarTable("UnitStudentdghhuesd3z1")]
|
|
public class Student : MongoDbBase
|
|
{
|
|
public string Name { get; set; }
|
|
|
|
public string SchoolId { get; set; }
|
|
|
|
public int Age { get; set; }
|
|
|
|
public DateTime CreateDateTime { get; set; }
|
|
}
|
|
}
|
|
}
|