mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 16:18:47 +08:00
Add demo
This commit is contained in:
parent
ddbc0214f7
commit
c7f6f9305d
@ -24,6 +24,7 @@ namespace OrmTest
|
|||||||
_a3_Merge.Init();
|
_a3_Merge.Init();
|
||||||
_a4_SplitTable.Init();
|
_a4_SplitTable.Init();
|
||||||
_a5_GridSave.Init();
|
_a5_GridSave.Init();
|
||||||
|
_a6_SqlPage.Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
<Compile Include="a3_Merge.cs" />
|
<Compile Include="a3_Merge.cs" />
|
||||||
<Compile Include="a4_SplitTable.cs" />
|
<Compile Include="a4_SplitTable.cs" />
|
||||||
<Compile Include="a5_GridSave.cs" />
|
<Compile Include="a5_GridSave.cs" />
|
||||||
|
<Compile Include="a6_SqlPage.cs" />
|
||||||
<Compile Include="UnitTest\Description.cs" />
|
<Compile Include="UnitTest\Description.cs" />
|
||||||
<Compile Include="3_EasyQuery.cs" />
|
<Compile Include="3_EasyQuery.cs" />
|
||||||
<Compile Include="7_GroupQuery.cs" />
|
<Compile Include="7_GroupQuery.cs" />
|
||||||
|
59
Src/Asp.Net/SqlServerTest/a6_SqlPage.cs
Normal file
59
Src/Asp.Net/SqlServerTest/a6_SqlPage.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
internal class _a6_SqlPage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes an example method for SQL paging operations.
|
||||||
|
/// 初始化 SQL 分页操作的示例方法。
|
||||||
|
/// </summary>
|
||||||
|
internal static void Init()
|
||||||
|
{
|
||||||
|
// Get a new database connection object
|
||||||
|
// 获取新的数据库连接对象
|
||||||
|
var db = DbHelper.GetNewDb();
|
||||||
|
|
||||||
|
// CodeFirst initializes the ClassA table
|
||||||
|
// CodeFirst 初始化 ClassA 表
|
||||||
|
db.CodeFirst.InitTables<ClassA>();
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
db.Insertable(new ClassA() { Name = Guid.NewGuid().ToString("N") }).ExecuteCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Query data using paging and get the total count
|
||||||
|
// 使用分页查询数据,并获取总记录数
|
||||||
|
int count = 0;
|
||||||
|
var list = db.SqlQueryable<ClassA>("select * from Table_a6").ToPageList(1, 5, ref count);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Asynchronously query data using paging and get the total count
|
||||||
|
// 使用异步方式分页查询数据,并获取总记录数
|
||||||
|
RefAsync<int> countAsync = 0;
|
||||||
|
var listAsync = db.SqlQueryable<ClassA>("select * from Table_a6").ToPageListAsync(1, 5, countAsync).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Example entity class.
|
||||||
|
/// 示例实体类。
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("Table_a6")]
|
||||||
|
public class ClassA
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user