mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Add user case test
This commit is contained in:
parent
458254d929
commit
4b03bf2b42
@ -32,6 +32,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitGridSave2.Init();
|
||||
Unitdfafa11.Init();
|
||||
UnitSelectN.Init();
|
||||
UnitSubqueryN.Init();
|
||||
|
@ -0,0 +1,81 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class UnitGridSave2
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
// Get a new database connection
|
||||
// 获取一个新的数据库连接
|
||||
SqlSugarClient db = NewUnitTest.Db;
|
||||
|
||||
// Initialize tables using CodeFirst
|
||||
// 使用 CodeFirst 初始化表
|
||||
db.CodeFirst.InitTables<Student>();
|
||||
|
||||
// Clear table data
|
||||
// 清空表数据
|
||||
db.DbMaintenance.TruncateTable<Student>();
|
||||
|
||||
// Insert two student records
|
||||
// 插入两条学生记录
|
||||
db.Insertable(new List<Student>() {
|
||||
new Student() {Name= "jack",CreateTime=DateTime.Now},
|
||||
new Student() {Name= "tom",CreateTime=DateTime.Now}
|
||||
}).ExecuteReturnIdentity();
|
||||
|
||||
// Query all student records
|
||||
// 查询所有学生记录
|
||||
List<Student> getAll = db.Queryable<Student>().ToList();
|
||||
|
||||
|
||||
|
||||
// Enable entity tracking for the list 'getAll'
|
||||
// 启用对列表 'getAll' 的实体跟踪
|
||||
db.Tracking(getAll);
|
||||
|
||||
|
||||
|
||||
|
||||
// Remove the first record
|
||||
// 移除第一条记录
|
||||
getAll.RemoveAt(0);
|
||||
|
||||
// Modify the name of the last record
|
||||
// 修改最后一条记录的姓名
|
||||
getAll[getAll.Count - 1].Name += "_Update";
|
||||
|
||||
// Add a new record
|
||||
// 添加新记录
|
||||
getAll.Add(new Student { Name = "NewRecord" });
|
||||
// Add a new record
|
||||
// 添加新记录
|
||||
getAll.Add(new Student { Name = "NewRecord" });
|
||||
|
||||
|
||||
// Execute GridSave operation
|
||||
// 执行 GridSave 操作
|
||||
db.GridSave(getAll).ExecuteCommand();
|
||||
|
||||
// Query all students again
|
||||
// 再次查询所有学生
|
||||
var list = db.Queryable<Student>().ToList();
|
||||
}
|
||||
|
||||
// Define the entity class 定义实体类
|
||||
[SugarTable("UnitSaveTablea5")]
|
||||
public class Student
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user