Update mongdob

This commit is contained in:
sunkaixuan
2025-07-17 12:56:45 +08:00
parent 63c368266a
commit 0aac4569a1
2 changed files with 38 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ namespace MongoDbTest
QueryLeftJoin2.Init();
QueryJsonArray.Init();
Insert.Init();
Insert2.Init();
Update.Init();
Delete.Init();
InsertOrUpdate.Init();

View File

@@ -0,0 +1,37 @@
using SqlSugar.MongoDb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace MongoDbTest
{
public class Insert2
{
internal static void Init()
{
var db = DbHelper.GetNewDb();
db.CodeFirst.InitTables<Student>();
db.DbMaintenance.TruncateTable<Student>();
//Get primary key
var data = new Student() { Age = 1, Name = "11", SchoolId = "111" };
db.Insertable(data).ExecuteCommandIdentityIntoEntity();
var data2=db.Queryable<Student>().ToList();
}
[SqlSugar.SugarTable("UnitStudentadsfe2s3z1")]
public class Student : MongoDbBase
{
public string Name { get; set; }
public string SchoolId { get; set; }
public int Age { get; set; }
[SqlSugar.SugarColumn(InsertServerTime =true)]
public DateTime CreateDateTime { get; set; }
}
}
}