mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Add demo
This commit is contained in:
@@ -32,6 +32,7 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
Unitdfaysss.Init();
|
||||||
Unitadfafasfa1.Init();
|
Unitadfafasfa1.Init();
|
||||||
Unita1ddys.Init();
|
Unita1ddys.Init();
|
||||||
Unit1sdgsaaysdfa.Init();
|
Unit1sdgsaaysdfa.Init();
|
||||||
|
63
Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitadfafayyss.cs
Normal file
63
Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitadfafayyss.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Unitdfaysss
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = NewUnitTest.Db;
|
||||||
|
//建表
|
||||||
|
db.CodeFirst.InitTables<Test001>();
|
||||||
|
|
||||||
|
|
||||||
|
//清空表
|
||||||
|
db.DbMaintenance.TruncateTable<Test001>();
|
||||||
|
|
||||||
|
//第一次插入测试数据,
|
||||||
|
var result = db.Insertable(new Test001() { Id = 1, Type = DemoType.示例 }).SplitTable().ExecuteCommand();//用例代码
|
||||||
|
|
||||||
|
// 获取所有拆分表
|
||||||
|
var tables = db.SplitHelper(typeof(Test001)).GetTables();
|
||||||
|
db.Aop.OnLogExecuting = (x, y) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(x);
|
||||||
|
|
||||||
|
};
|
||||||
|
DemoType? type = null;
|
||||||
|
// 更新所有拆分表
|
||||||
|
foreach (var item in tables)
|
||||||
|
{
|
||||||
|
db.Updateable<Test001>().AS(item.TableName)//使用分表名
|
||||||
|
.SetColumns(x => new Test001 { Type = type })
|
||||||
|
.Where(x => x.Id == 1)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
var xx = db.Queryable<Test001>().SplitTable().ToList();
|
||||||
|
if (xx.First().Type != null)
|
||||||
|
{
|
||||||
|
throw new Exception("unit test");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//建类
|
||||||
|
[SplitTable(SplitType.Year)]//按年度分表 (自带分表支持 年、季、月、周、日)
|
||||||
|
[SugarTable("test001_{year}{month}{day}")]
|
||||||
|
public class Test001
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public DemoType? Type { get; set; }
|
||||||
|
}
|
||||||
|
public enum DemoType
|
||||||
|
{
|
||||||
|
测试,
|
||||||
|
示例
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user