2023-11-06 08:07:42 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
2017-04-24 01:31:37 +08:00
|
|
|
|
|
2017-01-07 21:54:51 +08:00
|
|
|
|
namespace OrmTest
|
|
|
|
|
{
|
2023-11-06 08:07:42 +08:00
|
|
|
|
|
|
|
|
|
public class Program
|
2017-01-07 21:54:51 +08:00
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
2023-11-06 22:11:07 +08:00
|
|
|
|
{
|
|
|
|
|
//The statement translates to: "Each example will automatically create a table and can run independently."
|
|
|
|
|
//每个例子都会自动建表 并且可以独立运行 理解这话反应成英文
|
|
|
|
|
|
2023-11-06 08:07:42 +08:00
|
|
|
|
_1_CodeFirst.Init();
|
|
|
|
|
_2_DbFirst.Init();
|
2023-11-06 10:31:08 +08:00
|
|
|
|
_3_EasyQuery.Init();
|
2023-11-06 12:06:58 +08:00
|
|
|
|
_4_JoinQuery.Init();
|
2023-11-06 12:27:09 +08:00
|
|
|
|
_5_PageQuery.Init();
|
2023-11-06 18:39:00 +08:00
|
|
|
|
_6_NavQuery.Init();
|
|
|
|
|
_7_GroupQuery.Init();
|
2023-11-06 19:12:46 +08:00
|
|
|
|
_8_Insert.Init();
|
|
|
|
|
_9_Update.Init();
|
|
|
|
|
_a1_Delete.Init();
|
|
|
|
|
_a2_Sql.Init();
|
|
|
|
|
_a3_Merge.Init();
|
2017-01-07 21:54:51 +08:00
|
|
|
|
}
|
2023-11-06 08:07:42 +08:00
|
|
|
|
}
|
2019-05-05 14:28:54 +08:00
|
|
|
|
|
2023-11-06 08:07:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper class for database operations
|
|
|
|
|
/// 数据库操作的辅助类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DbHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Database connection string
|
|
|
|
|
/// 数据库连接字符串
|
|
|
|
|
/// </summary>
|
2023-11-06 08:29:41 +08:00
|
|
|
|
public readonly static string Connection = "server=.;uid=sa;pwd=sasa;database=SqlSugar5Demo";
|
2022-11-03 09:38:24 +08:00
|
|
|
|
|
2023-11-06 08:07:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get a new SqlSugarClient instance with specific configurations
|
|
|
|
|
/// 获取具有特定配置的新 SqlSugarClient 实例
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>SqlSugarClient instance</returns>
|
|
|
|
|
public static SqlSugarClient GetNewDb()
|
|
|
|
|
{
|
|
|
|
|
var db = new SqlSugarClient(new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
|
IsAutoCloseConnection = true,
|
|
|
|
|
DbType = DbType.SqlServer,
|
2023-11-06 10:57:44 +08:00
|
|
|
|
ConnectionString = Connection,
|
|
|
|
|
LanguageType=LanguageType.Default//Set language
|
|
|
|
|
|
2023-11-06 08:07:42 +08:00
|
|
|
|
},
|
|
|
|
|
it => {
|
|
|
|
|
// Logging SQL statements and parameters before execution
|
|
|
|
|
// 在执行前记录 SQL 语句和参数
|
|
|
|
|
it.Aop.OnLogExecuting = (sql, para) =>
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(UtilMethods.GetNativeSql(sql, para));
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return db;
|
|
|
|
|
}
|
2017-01-07 21:54:51 +08:00
|
|
|
|
}
|
2023-11-06 08:07:42 +08:00
|
|
|
|
}
|