From 891f0af03163e390c87e9a26fca6abe1134993c1 Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Fri, 12 Apr 2024 19:20:57 +0800
Subject: [PATCH] Add user test case
---
.../PgSqlTest/UserTestCases/Main.cs | 1 +
.../PgSqlTest/UserTestCases/Unitadfay.cs | 131 ++++++++++++++++++
2 files changed, 132 insertions(+)
create mode 100644 Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitadfay.cs
diff --git a/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs
index a9749a433..85be1550c 100644
--- a/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs
+++ b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs
@@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
+ Unitadfaf2s.Init();
UnitWeek.Init();
UnitTestOneToOne.Init();
Unitadfafafasd.Init();
diff --git a/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitadfay.cs b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitadfay.cs
new file mode 100644
index 000000000..213ba2fbb
--- /dev/null
+++ b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitadfay.cs
@@ -0,0 +1,131 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ ///
+ /// Class for demonstrating CodeFirst initialization operations
+ /// 用于展示 CodeFirst 初始化操作的类
+ ///
+ public class Unitadfaf2s
+ {
+
+ public static void Init()
+ {
+ // Get a new database instance
+ // 获取新的数据库实例
+ var db = DbHelper.GetNewDb();
+
+ // Create the database if it doesn't exist
+ // 如果数据库不存在,则创建数据库
+ db.DbMaintenance.CreateDatabase();
+
+ // Initialize tables based on UserInfo001 entity class
+ // 根据 UserInfo001 实体类初始化表
+ db.CodeFirst.InitTables();
+
+ db.DbMaintenance.TruncateTable();
+ //Insert
+
+ var id = db.Insertable(
+ new UserInfo001xdxx1()
+ {
+ Context = "Context",
+ Email = "dfafa@qq.com",
+ Price = Convert.ToDecimal(1.1),
+ UserName = "admin",
+ RegistrationDate = DateTime.MaxValue,
+
+ }).ExecuteReturnIdentity();
+ //插入
+ var id2 = db.Insertable(new List() {
+ new UserInfo001xdxx1()
+ {
+ Context = "Context",
+ Email="dfafa@qq.com",
+ Price=Convert.ToDecimal(1.1),
+ UserName="admin",
+ RegistrationDate=DateTime.MaxValue,
+
+ },
+ new UserInfo001xdxx1()
+ {
+ Context = "Context",
+ Email="dfafa@qq.com",
+ Price=Convert.ToDecimal(1.1),
+ UserName="admin",
+ RegistrationDate=DateTime.MaxValue,
+
+ }
+ }).ExecuteReturnIdentity();
+
+ var xxx = db.Queryable().ToList();
+ //Query
+ //查询
+ var userInfo = db.Queryable().InSingle(id);
+
+ //Update
+ //更新
+ db.Updateable(userInfo).ExecuteCommand();
+
+ //Delete
+ //删除
+ db.Deleteable(userInfo).ExecuteCommand();
+ }
+
+ ///
+ /// User information entity class
+ /// 用户信息实体类
+ ///
+ public class UserInfo001xdxx1
+ {
+ ///
+ /// User ID (Primary Key)
+ /// 用户ID(主键)
+ ///
+ [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
+ public int UserId { get; set; }
+
+ ///
+ /// User name
+ /// 用户名
+ ///
+ [SugarColumn(Length = 50, IsNullable = false)]
+ public string UserName { get; set; }
+
+ ///
+ /// User email
+ /// 用户邮箱
+ ///
+ [SugarColumn(IsNullable = true)]
+ public string Email { get; set; }
+
+
+ ///
+ /// Product price
+ /// 产品价格
+ ///
+ public decimal Price { get; set; }
+
+ ///
+ /// User context
+ /// 用户内容
+ ///
+ [SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
+ public string Context { get; set; }
+
+ ///
+ /// User registration date
+ /// 用户注册日期
+ ///
+ [SugarColumn(IsNullable = true, ColumnDataType = "timestamp with time zone")]
+ public DateTime? RegistrationDate { get; set; }
+ }
+
+
+ }
+}
\ No newline at end of file