diff --git a/.github/workflows/docfx.yml b/.github/workflows/docfx.yml
new file mode 100644
index 00000000..8cca960d
--- /dev/null
+++ b/.github/workflows/docfx.yml
@@ -0,0 +1,58 @@
+name: .NET Core Deploy Docfx
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+ branches: [master]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ - name: Setup .NET Core
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 5.0.202
+ - name: Exclude example projects
+ run: dotnet sln FreeSql.sln remove Examples/**/*.csproj FreeSql.Tests/**/*.csproj
+ - name: Install dependencies
+ run: dotnet restore
+ - name: Build solution
+ run: dotnet build --configuration Release --no-restore
+
+ generate-docs:
+ runs-on: windows-latest
+ needs: build
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ - name: Setup .NET Core
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 5.0.202
+ - name: Remove Examples
+ run: dotnet sln FreeSql.sln remove (ls -r Examples/**/*.csproj)
+ - name: Remove FreeSql.Tests
+ run: dotnet sln FreeSql.sln remove (ls -r FreeSql.Tests/**/*.csproj)
+ - name: Install dependencies
+ run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config && dotnet restore
+ - name: Setup DocFX
+ uses: crazy-max/ghaction-chocolatey@v1
+ with:
+ args: install docfx --version 2.56.7
+ - name: DocFX Build
+ working-directory: docs
+ run: docfx docfx.json
+ continue-on-error: false
+ - name: Publish
+ if: github.event_name == 'push'
+ uses: peaceiris/actions-gh-pages@v3
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ publish_dir: docs/_site
+ force_orphan: true
diff --git a/Examples/repository_01/Controllers/SongController.cs b/Examples/repository_01/Controllers/SongController.cs
index 4381d575..a6bb50de 100644
--- a/Examples/repository_01/Controllers/SongController.cs
+++ b/Examples/repository_01/Controllers/SongController.cs
@@ -63,6 +63,17 @@ namespace restful.Controllers
return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
}
+ ///
+ /// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
+ ///
+ ///
+ ///
+ [HttpGet("GetPagingItems")]
+ public Task> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
+ {
+ return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
+ }
+
[HttpGet("{id}")]
public Task GetItem([FromRoute] int id)
{
diff --git a/Examples/repository_01/PagingInfo.cs b/Examples/repository_01/PagingInfo.cs
new file mode 100644
index 00000000..803ec20c
--- /dev/null
+++ b/Examples/repository_01/PagingInfo.cs
@@ -0,0 +1,57 @@
+using FreeSql.Internal.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace repository_01
+{
+ public class PagingInfo : BasePagingInfo
+ {
+ ///
+ /// 无参构造函数
+ ///
+ public PagingInfo()
+ {
+ }
+ ///
+ /// 当前为第1页,每页大小的构造函数
+ ///
+ ///
+ public PagingInfo(int pageSize)
+ {
+ PageNumber = 1;
+ PageSize = pageSize;
+ }
+ ///
+ /// 带当前页和每页大小的构造函数
+ ///
+ ///
+ ///
+ public PagingInfo(int pageNumber, int pageSize)
+ {
+ PageNumber = pageNumber;
+ PageSize = pageSize;
+ }
+ ///
+ /// 当前有多少页【只读】
+ ///
+ public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
+ ///
+ /// 是否有上一页【只读】
+ ///
+ public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
+ ///
+ /// 是否有下一页【只读】
+ ///
+ public bool HasNext => PageNumber < PageCount;
+ ///
+ /// 是否在第一页【只读】
+ ///
+ public bool IsFrist => PageNumber == 1;
+ ///
+ /// 是否在最后一页【只读】
+ ///
+ public bool IsLast => PageNumber == PageCount;
+ }
+}
\ No newline at end of file
diff --git a/Examples/restful/Controllers/SongController.cs b/Examples/restful/Controllers/SongController.cs
index 0cd631ae..98980779 100644
--- a/Examples/restful/Controllers/SongController.cs
+++ b/Examples/restful/Controllers/SongController.cs
@@ -25,6 +25,18 @@ namespace restful.Controllers
return _fsql.Select().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
}
+ ///
+ /// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
+ ///
+ ///
+ ///
+ ///
+ [HttpGet("GetPagingItems")]
+ public Task> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
+ {
+ return _fsql.Select().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
+ }
+
[HttpGet("{id}")]
public Task GetItem([FromRoute] int id)
{
diff --git a/Examples/restful/PagingInfo.cs b/Examples/restful/PagingInfo.cs
new file mode 100644
index 00000000..ab52c180
--- /dev/null
+++ b/Examples/restful/PagingInfo.cs
@@ -0,0 +1,57 @@
+using FreeSql.Internal.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace restful
+{
+ public class PagingInfo : BasePagingInfo
+ {
+ ///
+ /// 无参构造函数
+ ///
+ public PagingInfo()
+ {
+ }
+ ///
+ /// 当前为第1页,每页大小的构造函数
+ ///
+ ///
+ public PagingInfo(int pageSize)
+ {
+ PageNumber = 1;
+ PageSize = pageSize;
+ }
+ ///
+ /// 带当前页和每页大小的构造函数
+ ///
+ ///
+ ///
+ public PagingInfo(int pageNumber, int pageSize)
+ {
+ PageNumber = pageNumber;
+ PageSize = pageSize;
+ }
+ ///
+ /// 当前有多少页【只读】
+ ///
+ public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
+ ///
+ /// 是否有上一页【只读】
+ ///
+ public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
+ ///
+ /// 是否有下一页【只读】
+ ///
+ public bool HasNext => PageNumber < PageCount;
+ ///
+ /// 是否在第一页【只读】
+ ///
+ public bool IsFrist => PageNumber == 1;
+ ///
+ /// 是否在最后一页【只读】
+ ///
+ public bool IsLast => PageNumber == PageCount;
+ }
+}
\ No newline at end of file
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index ad59871a..892888fe 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -2136,6 +2136,13 @@
每页多少
+
+
+ 分页
+
+ 分页信息
+
+
查询数据前,去重
@@ -2607,6 +2614,13 @@
每页多少
+
+
+ 分页
+
+ 分页信息
+
+
查询的记录数量
@@ -3976,6 +3990,26 @@
+
+
+ 分页信息
+
+
+
+
+ 第几页,从1开始
+
+
+
+
+ 每页多少
+
+
+
+
+ 查询的记录数量
+
+
当前操作的数据
diff --git a/FreeSql/Interface/Curd/ISelect/ISelect0.cs b/FreeSql/Interface/Curd/ISelect/ISelect0.cs
index 1ecab564..d17490da 100644
--- a/FreeSql/Interface/Curd/ISelect/ISelect0.cs
+++ b/FreeSql/Interface/Curd/ISelect/ISelect0.cs
@@ -402,6 +402,13 @@ namespace FreeSql
///
TSelect Page(int pageNumber, int pageSize);
+ ///
+ /// 分页
+ ///
+ /// 分页信息
+ ///
+ TSelect Page(BasePagingInfo pagingInfo);
+
///
/// 查询数据前,去重
///
diff --git a/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs b/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs
index 295b7411..c787cc61 100644
--- a/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs
+++ b/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs
@@ -1,4 +1,5 @@
-using System;
+using FreeSql.Internal.Model;
+using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
@@ -101,6 +102,13 @@ namespace FreeSql
///
ISelectGrouping Page(int pageNumber, int pageSize);
+ ///
+ /// 分页
+ ///
+ /// 分页信息
+ ///
+ ISelectGrouping Page(BasePagingInfo pagingInfo);
+
///
/// 查询的记录数量
///
diff --git a/FreeSql/Internal/CommonProvider/InsertProvider.cs b/FreeSql/Internal/CommonProvider/InsertProvider.cs
index 1a1378b7..5a2b62cb 100644
--- a/FreeSql/Internal/CommonProvider/InsertProvider.cs
+++ b/FreeSql/Internal/CommonProvider/InsertProvider.cs
@@ -179,7 +179,7 @@ namespace FreeSql.Internal.CommonProvider
}
if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false)
col.SetValue(data, val = "");
- if (val == null && col.Attribute.MapType == typeof(byte[]) && col.Attribute.IsVersion)
+ if (col.Attribute.MapType == typeof(byte[]) && (val == null || (val is byte[] bytes && bytes.Length == 0)) && col.Attribute.IsVersion)
col.SetValue(data, val = Utils.GuidToBytes(Guid.NewGuid()));
}
}
diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
index 74cfd9f3..d82980eb 100644
--- a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
+++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
@@ -319,6 +319,13 @@ namespace FreeSql.Internal.CommonProvider
return this.Limit(pageSize) as TSelect;
}
+ public TSelect Page(BasePagingInfo pagingInfo)
+ {
+ pagingInfo.Count = this.Count();
+ this.Skip(Math.Max(0, pagingInfo.PageNumber - 1) * pagingInfo.PageSize);
+ return this.Limit(pagingInfo.PageSize) as TSelect;
+ }
+
public TSelect Skip(int offset)
{
_skip = offset;
diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs
index 09c524e0..68ca4c50 100644
--- a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs
+++ b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs
@@ -201,6 +201,14 @@ namespace FreeSql.Internal.CommonProvider
return this;
}
+ public ISelectGrouping Page(BasePagingInfo pagingInfo)
+ {
+ pagingInfo.Count = this.Count();
+ _groupBySkip = Math.Max(0, pagingInfo.PageNumber - 1) * pagingInfo.PageSize;
+ _groupByLimit = pagingInfo.PageSize;
+ return this;
+ }
+
public long Count() => _select._cancel?.Invoke() == true ? 0 : long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_select._connection, _select._transaction, CommandType.Text, $"select count(1) from ({this.ToSql($"1{_comonExp._common.FieldAsAlias("as1")}")}) fta", _select._commandTimeout, _select._params.ToArray())), out var trylng) ? trylng : default(long);
public ISelectGrouping Count(out long count)
{
diff --git a/FreeSql/Internal/Model/BasePagingInfo.cs b/FreeSql/Internal/Model/BasePagingInfo.cs
new file mode 100644
index 00000000..2a48e529
--- /dev/null
+++ b/FreeSql/Internal/Model/BasePagingInfo.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace FreeSql.Internal.Model
+{
+ ///
+ /// 分页信息
+ ///
+ public class BasePagingInfo
+ {
+ ///
+ /// 第几页,从1开始
+ ///
+ public int PageNumber { get; set; }
+ ///
+ /// 每页多少
+ ///
+ public int PageSize { get; set; }
+ ///
+ /// 查询的记录数量
+ ///
+ public long Count { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index 4cfa8d36..b44fdc19 100644
--- a/README.md
+++ b/README.md
@@ -206,7 +206,7 @@ constantine,
L*y 58元、花花 88元、麦兜很乖 50元、网络来者 2000元、John 99.99元、alex 666元、bacongao 36元、无名 100元、Eternity 188元、无名 10元、⌒.Helper~..oO 66元、习惯与被习惯 100元、无名 100元、蔡易喋 88.88元、中讯科技 1000元、Good Good Work 24元、炽焰 6.6元、Nothing 100元、兰州天擎赵 500元、哈利路亚 300元、
无名 100元、蛰伏 99.99元、TCYM 66.66元、MOTA 5元、LDZXG 30元、Near 30元、建爽 66元、无名 200元、LambertWu 100元、无名 18.88元、乌龙 50元、无名 100元、陳怼怼 66.66元、陳怼怼 66.66元、丁淮 100元、李伟坚-Excel催化剂 100元、白狐 6.66元、她微笑的脸y 30元、Eternity²º²¹ 588元、夜归柴门 88元、蔡易喋 666.66元、
-*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k\*t 66元、蓝 100元
+*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k\*t 66元、蓝 100元、*菜 10元、生命如歌 1000元
> Thank you for your donation
diff --git a/README.zh-CN.md b/README.zh-CN.md
index c5d9040c..3873c4fd 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -210,7 +210,7 @@ constantine,
L*y 58元、花花 88元、麦兜很乖 50元、网络来者 2000元、John 99.99元、alex 666元、bacongao 36元、无名 100元、Eternity 188元、无名 10元、⌒.Helper~..oO 66元、习惯与被习惯 100元、无名 100元、蔡易喋 88.88元、中讯科技 1000元、Good Good Work 24元、炽焰 6.6元、Nothing 100元、兰州天擎赵 500元、哈利路亚 300元、
无名 100元、蛰伏 99.99元、TCYM 66.66元、MOTA 5元、LDZXG 30元、Near 30元、建爽 66元、无名 200元、LambertWu 100元、无名 18.88元、乌龙 50元、无名 100元、陳怼怼 66.66元、陳怼怼 66.66元、丁淮 100元、李伟坚-Excel催化剂 100元、白狐 6.66元、她微笑的脸y 30元、Eternity²º²¹ 588元、夜归柴门 88元、蔡易喋 666.66元、
-*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k*t 66元、蓝 100元
+*礼 10元、litrpa 88元、Alax CHOW 200元、Daily 66元、k*t 66元、蓝 100元、*菜 10元、生命如歌 1000元
> 超级感谢你的打赏。
diff --git a/docs/.gitignore b/docs/.gitignore
new file mode 100644
index 00000000..d5705ab8
--- /dev/null
+++ b/docs/.gitignore
@@ -0,0 +1,15 @@
+###############
+# folder #
+###############
+/**/DROP/
+/**/TEMP/
+/**/packages/
+/**/bin/
+/**/obj/
+_site
+/freesql/provider/*.yml
+/freesql/provider/.manifest
+/freesql/repository/*.yml
+/freesql/repository/.manifest
+/api/*.yml
+/api/.manifest
\ No newline at end of file
diff --git a/docs/README.md b/docs/README.md
new file mode 100644
index 00000000..df64eec7
--- /dev/null
+++ b/docs/README.md
@@ -0,0 +1,14 @@
+
+### DocFX
+- https://dotnet.github.io/docfx/tutorial/docfx_getting_started.html
+
+
+run
+
+```
+docfx docfx_project\docfx.json --serve
+
+or
+
+docfx .\docfx.json --serve
+```
\ No newline at end of file
diff --git a/docs/api/index.md b/docs/api/index.md
new file mode 100644
index 00000000..22d15855
--- /dev/null
+++ b/docs/api/index.md
@@ -0,0 +1,2 @@
+# FreeSql
+TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*!
diff --git a/docs/docfx.json b/docs/docfx.json
new file mode 100644
index 00000000..cad8bbd4
--- /dev/null
+++ b/docs/docfx.json
@@ -0,0 +1,137 @@
+{
+ "metadata": [
+ {
+ "src": [
+ {
+ "files": [
+ "FreeSql/*.csproj"
+ ],
+ "exclude": [
+ "**/bin/**",
+ "**/obj/**"
+ ],
+ "src": "../"
+ }
+ ],
+ "dest": "api",
+ "disableGitFeatures": false,
+ "disableDefaultFilter": false
+ },
+ {
+ "src": [
+ {
+ "files": [
+ "FreeSql.DbContext/*.csproj",
+ "FreeSql.Repository/*.csproj"
+ ],
+ "exclude": [
+ "**/bin/**",
+ "**/obj/**"
+ ],
+ "src": "../"
+ }
+ ],
+ "dest": "freesql/repository",
+ "disableGitFeatures": false,
+ "disableDefaultFilter": false
+ },
+ {
+ "src": [
+ {
+ "files": [
+ "Providers/FreeSql.Provider.MySql/*.csproj",
+ "Providers/FreeSql.Provider.Dameng/*.csproj",
+ "Providers/FreeSql.Provider.KingbaseES/*.csproj",
+ "Providers/FreeSql.Provider.MsAccess/*.csproj",
+ "Providers/FreeSql.Provider.MySqlConnector/*.csproj",
+ "Providers/FreeSql.Provider.Odbc/*.csproj",
+ "Providers/FreeSql.Provider.Oracle/*.csproj",
+ "Providers/FreeSql.Provider.PostgreSQL/*.csproj",
+ "Providers/FreeSql.Provider.ShenTong*.csproj",
+ "Providers/FreeSql.Provider.Sqlite/*.csproj",
+ "Providers/FreeSql.Provider.SqlServer/*.csproj",
+ "Providers/FreeSql.Provider.SqlServerForSystem/*.csproj"
+ ],
+ "exclude": [
+ "**/bin/**",
+ "**/obj/**"
+ ],
+ "src": "../"
+ }
+ ],
+ "dest": "freesql/provider",
+ "disableGitFeatures": false,
+ "disableDefaultFilter": false
+ }
+ ],
+ "build": {
+ "content": [
+ {
+ "files": [
+ "api/**.yml",
+ "api/index.md"
+ ]
+ },
+ {
+ "files": [
+ "freesql/repository/**.yml",
+ "freesql/repository/index.md"
+ ]
+ },
+ {
+ "files": [
+ "freesql/provider/**.yml",
+ "freesql/provider/index.md"
+ ]
+ },
+ {
+ "files": [
+ "articles/**.md",
+ "articles/**/toc.yml",
+ "toc.yml",
+ "*.md"
+ ]
+ }
+ ],
+ "resource": [
+ {
+ "files": [
+ "images/**",
+ "styles/**"
+ ]
+ }
+ ],
+ "overwrite": [
+ {
+ "files": [
+ "Docs/**.md"
+ ],
+ "exclude": [
+ "obj/**",
+ "_site/**"
+ ]
+ }
+ ],
+ "dest": "_site",
+ "globalMetadataFiles": [],
+ "fileMetadataFiles": [],
+ "template": [
+ "default"
+ ],
+ "globalMetadata": {
+ "_appTitle": "FreeSql API Docs",
+ "_appLogoPath": "./images/logo.svg",
+ "_gitContribute": {
+ "repo": "https://github.com/dotnetcore/freesql",
+ "branch": "master"
+ },
+ "_enableSearch": true
+ },
+ "postProcessors": [],
+ "markdownEngineName": "markdig",
+ "noLangKeyword": false,
+ "keepFileLink": false,
+ "cleanupCacheHistory": false,
+ "disableGitFeatures": false
+ }
+}
\ No newline at end of file
diff --git a/docs/freesql/provider/index.md b/docs/freesql/provider/index.md
new file mode 100644
index 00000000..e69de29b
diff --git a/docs/freesql/repository/index.md b/docs/freesql/repository/index.md
new file mode 100644
index 00000000..726a58de
--- /dev/null
+++ b/docs/freesql/repository/index.md
@@ -0,0 +1,2 @@
+# repository
+TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*!
diff --git a/docs/images/logo.svg b/docs/images/logo.svg
new file mode 100644
index 00000000..0af3c572
--- /dev/null
+++ b/docs/images/logo.svg
@@ -0,0 +1,104 @@
+
+
+
diff --git a/docs/index.md b/docs/index.md
new file mode 100644
index 00000000..f63cb3c6
--- /dev/null
+++ b/docs/index.md
@@ -0,0 +1,11 @@
+
+# FreeSql Document
+
+#### [http://freesql.net](http://freesql.net)
+
+
+
+ .NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, MsAccess orm.
+
+ - Github [https://github.com/dotnetcore/freesql](https://github.com/dotnetcore/freesql)
+ - Gitee [https://gitee.com/FreeSql/FreeSql-ORM](https://gitee.com/FreeSql/FreeSql-ORM)
diff --git a/docs/toc.yml b/docs/toc.yml
new file mode 100644
index 00000000..e9b1d962
--- /dev/null
+++ b/docs/toc.yml
@@ -0,0 +1,11 @@
+- name: FreeSql Documentation
+ href: api/
+ homepage: api/index.md
+
+- name: Repository Documentation
+ href: freesql/repository/
+ homepage: freesql/repository/index.md
+
+- name: Provider Documentation
+ href: freesql/provider/
+ homepage: freesql/provider/index.md