diff --git a/Src/Asp.Net/SqlServerTest/Program.cs b/Src/Asp.Net/SqlServerTest/Program.cs index e83e9035c..1fa8a1d44 100644 --- a/Src/Asp.Net/SqlServerTest/Program.cs +++ b/Src/Asp.Net/SqlServerTest/Program.cs @@ -24,6 +24,7 @@ namespace OrmTest _a3_Merge.Init(); _a4_SplitTable.Init(); _a5_GridSave.Init(); + _a6_SqlPage.Init(); } } diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index e96b03c14..7186f67b5 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -74,6 +74,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/a6_SqlPage.cs b/Src/Asp.Net/SqlServerTest/a6_SqlPage.cs new file mode 100644 index 000000000..47a67aaef --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/a6_SqlPage.cs @@ -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 + { + /// + /// + /// Initializes an example method for SQL paging operations. + /// 初始化 SQL 分页操作的示例方法。 + /// + internal static void Init() + { + // Get a new database connection object + // 获取新的数据库连接对象 + var db = DbHelper.GetNewDb(); + + // CodeFirst initializes the ClassA table + // CodeFirst 初始化 ClassA 表 + db.CodeFirst.InitTables(); + 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("select * from Table_a6").ToPageList(1, 5, ref count); + + + + // Asynchronously query data using paging and get the total count + // 使用异步方式分页查询数据,并获取总记录数 + RefAsync countAsync = 0; + var listAsync = db.SqlQueryable("select * from Table_a6").ToPageListAsync(1, 5, countAsync).GetAwaiter().GetResult(); + } + + /// + /// Example entity class. + /// 示例实体类。 + /// + [SugarTable("Table_a6")] + public class ClassA + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + public string Name { get; set; } + } + } +} \ No newline at end of file