From 46c352016a81d35d3f749ae8d5e611dedba1019d Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Thu, 27 Feb 2020 17:56:34 +0800 Subject: [PATCH] update --- Home.md | 3 +- LinqToSql.md | 1 - _Sidebar.md | 1 - 修改.md | 2 +- 分区分表.md | 2 +- 分组聚合查询.md | 3 +- 分页查询.md | 3 +- 删除.md | 2 +- 利用导航属性.md | 70 ------------------------------ 单表查询.md | 1 - 多表查询.md | 1 - 安装.md | 1 - 工作单元.md | 2 +- 延时加载.md | 1 - 性能.md | 1 - 查询.md | 1 - 添加.md | 2 +- 缓存.md | 49 --------------------- 联级保存.md | 4 +- 表达式函数.md | 1 - 贪婪加载.md | 13 +++--- 过滤器.md | 8 ++-- 返回数据.md | 111 +++++++++++++----------------------------------- 23 files changed, 51 insertions(+), 232 deletions(-) delete mode 100644 利用导航属性.md delete mode 100644 缓存.md diff --git a/Home.md b/Home.md index db850a9..c560c78 100644 --- a/Home.md +++ b/Home.md @@ -10,7 +10,7 @@ FreeSql是一个功能强大的NETStandard库,用于对象关系映射程序(O - [x] 支持导航属性查询,和延时加载; - [x] 支持同步/异步数据库操作方法,丰富多彩的链式查询方法; - [x] 支持读写分离、分表分库,租户设计; -- [x] 支持多种数据库,MySql/SqlServer/PostgreSQL/Oracle/Sqlite/达梦; +- [x] 支持多种数据库,MySql/SqlServer/PostgreSQL/Oracle/Sqlite/达梦/MsAccess; * [FreeSql入门](https://github.com/2881099/FreeSql/wiki/FreeSql%e5%85%a5%e9%97%a8) * [安装](https://github.com/2881099/FreeSql/wiki/%e5%ae%89%e8%a3%85) @@ -29,7 +29,6 @@ FreeSql是一个功能强大的NETStandard库,用于对象关系映射程序(O * [分页](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e9%a1%b5%e6%9f%a5%e8%af%a2) * [单表](https://github.com/2881099/FreeSql/wiki/%e5%8d%95%e8%a1%a8%e6%9f%a5%e8%af%a2) * [多表](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) - * [利用导航属性](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) * [分组聚合](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e7%bb%84%e8%81%9a%e5%90%88%e6%9f%a5%e8%af%a2) * [返回数据!!](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) * [延时加载](https://github.com/2881099/FreeSql/wiki/%e5%bb%b6%e6%97%b6%e5%8a%a0%e8%bd%bd) diff --git a/LinqToSql.md b/LinqToSql.md index c72b883..3a17fc3 100644 --- a/LinqToSql.md +++ b/LinqToSql.md @@ -147,7 +147,6 @@ var t1 = ( ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) - [《优化之:延时加载》](https://github.com/2881099/FreeSql/wiki/%e5%bb%b6%e6%97%b6%e5%8a%a0%e8%bd%bd) diff --git a/_Sidebar.md b/_Sidebar.md index bf09534..16b1d52 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -17,7 +17,6 @@ * [分页](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e9%a1%b5%e6%9f%a5%e8%af%a2) * [单表](https://github.com/2881099/FreeSql/wiki/%e5%8d%95%e8%a1%a8%e6%9f%a5%e8%af%a2) * [多表](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) - * [利用导航属性](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) * [分组聚合](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e7%bb%84%e8%81%9a%e5%90%88%e6%9f%a5%e8%af%a2) * [返回数据!!](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) * [延时加载](https://github.com/2881099/FreeSql/wiki/%e5%bb%b6%e6%97%b6%e5%8a%a0%e8%bd%bd) diff --git a/修改.md b/修改.md index e9bc192..7c208d7 100644 --- a/修改.md +++ b/修改.md @@ -4,7 +4,7 @@ FreeSql支持丰富的更新数据方法,支持单条或批量更新,在特 var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + "Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10"; -IFreeSql fsql = new FreeSql.FreeSqlBuilder() +static IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, connstr) .UseAutoSyncStructure(true) //自动同步实体结构到数据库 .Build(); //请务必定义成 Singleton 单例模式 diff --git a/分区分表.md b/分区分表.md index ab68aac..0132c5d 100644 --- a/分区分表.md +++ b/分区分表.md @@ -38,7 +38,7 @@ create table fenbiao_2018 partition of fenbiao for values in ('2018'); 数据库中的数据量不一定是可控的,在未进行分库分表的情况下,随着时间和业务的发展,库中的表会越来越多,表中的数据量也会越来越大,相应地,数据操作,增删改查的开销也会越来越大;另外,一台服务器的资源(CPU、磁盘、内存、IO等)是有限的,最终数据库所能承载的数据量、数据处理能力都将遭遇瓶颈。 -## FreeSql.Repository 之分表 +## FreeSql.Repository 分表 FreeSql 提供 AsTable 分表的基础方法,GuidRepository 作为分存式仓储将实现了分表与分库(不支持跨服务器分库)的封装。 diff --git a/分组聚合查询.md b/分组聚合查询.md index 2d5fe5c..d0eb9f5 100644 --- a/分组聚合查询.md +++ b/分组聚合查询.md @@ -1,5 +1,5 @@ ```csharp -IFreeSql fsql = new FreeSql.FreeSqlBuilder() +static IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10") .Build(); //请务必定义成 Singleton 单例模式 @@ -55,7 +55,6 @@ var groupby = fsql.Select() ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) diff --git a/分页查询.md b/分页查询.md index 214bec3..a59c4c9 100644 --- a/分页查询.md +++ b/分页查询.md @@ -1,5 +1,5 @@ ```csharp -IFreeSql fsql = new FreeSql.FreeSqlBuilder() +static IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10") .Build(); //请务必定义成 Singleton 单例模式 @@ -51,7 +51,6 @@ SqlServer 2012+ 版本,使用最新的 fetch next rows 分页; ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) diff --git a/删除.md b/删除.md index dc21a69..d880d12 100644 --- a/删除.md +++ b/删除.md @@ -10,7 +10,7 @@ var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + "Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10"; -IFreeSql fsql = new FreeSql.FreeSqlBuilder() +static IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, connstr) .UseAutoSyncStructure(true) //自动同步实体结构到数据库 .Build(); //请务必定义成 Singleton 单例模式 diff --git a/利用导航属性.md b/利用导航属性.md deleted file mode 100644 index eab537d..0000000 --- a/利用导航属性.md +++ /dev/null @@ -1,70 +0,0 @@ -```csharp -IFreeSql fsql = new FreeSql.FreeSqlBuilder() - .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10") - .Build(); //请务必定义成 Singleton 单例模式 - -[Table(Name = "tb_topic")] -class Topic { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TestTypeInfoGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } -} -class TestTypeInfo { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } -} -class TestTypeParentInfo { - public int Id { get; set; } - public string Name { get; set; } -} - -ISelect select => fsql.Select(); -``` - -### 联表,使用导航属性 -```csharp -sql = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).ToSql(); -//SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a__Type.`Guid`, a__Type.`ParentId`, a__Type.`Name`, a.`Title`, a.`CreateTime` -//FROM `tb_topic` a -//LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid` - -sql = select - .LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid) - .LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).ToSql(); -//SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a__Type.`Guid`, a__Type.`ParentId`, a__Type.`Name`, a.`Title`, a.`CreateTime` -//FROM `tb_topic` a -//LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid` -//LEFT JOIN `TestTypeParentInfo` a__Type__Parent ON a__Type__Parent.`Id` = a__Type.`ParentId` -``` - -## 多表,使用导航属性 -```csharp -sql = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TestTypeInfoGuid).ToSql(); -///SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a.`Title`, a.`CreateTime` -//FROM `tb_topic` a, `TestTypeInfo` a__Type -//WHERE (a__Type.`Name` = 'typeTitle' AND a__Type.`Guid` = a.`TestTypeInfoGuid`) - -sql = select.Where(a => a.Type.Parent.Name == "tparent").ToSql(); -//SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a.`Title`, a.`CreateTime` -//FROM `tb_topic` a, `TestTypeInfo` a__Type, `TestTypeParentInfo` a__Type__Parent -//WHERE (a__Type__Parent.`Name` = 'tparent') -``` - -## 参考资料 - -- [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) -- [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) -- [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) -- [《优化之:延时加载》](https://github.com/2881099/FreeSql/wiki/%e5%bb%b6%e6%97%b6%e5%8a%a0%e8%bd%bd) -- [《优化之:贪婪加载》](https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd) -- [《Expression 表达式函数》](https://github.com/2881099/FreeSql/wiki/%e8%a1%a8%e8%be%be%e5%bc%8f%e5%87%bd%e6%95%b0) -- [《性能》](https://github.com/2881099/FreeSql/wiki/%e6%80%a7%e8%83%bd) -- [《分区、分表、分库》](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e5%8c%ba%e5%88%86%e8%a1%a8) -- [《租户》](https://github.com/2881099/FreeSql/wiki/%e7%a7%9f%e6%88%b7) \ No newline at end of file diff --git a/单表查询.md b/单表查询.md index a31d1ac..5ef31d8 100644 --- a/单表查询.md +++ b/单表查询.md @@ -45,7 +45,6 @@ var sql = fsql.Select() ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) diff --git a/多表查询.md b/多表查询.md index 58e3742..cdd3720 100644 --- a/多表查询.md +++ b/多表查询.md @@ -162,7 +162,6 @@ WHERE t1.IsDeleted = 0 ## 参考资料 -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) diff --git a/安装.md b/安装.md index 7929605..8f2dc42 100644 --- a/安装.md +++ b/安装.md @@ -36,7 +36,6 @@ FreeSql 除了支持基本的增删查改功能外,还支持基于现有数据 - [《使用读写分离》](https://github.com/2881099/FreeSql/wiki/%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb) - [《分区、分表、分库》](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e5%8c%ba%e5%88%86%e8%a1%a8) - [《租户》](https://github.com/2881099/FreeSql/wiki/%e7%a7%9f%e6%88%b7) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《优化之:延时加载》](https://github.com/2881099/FreeSql/wiki/%e5%bb%b6%e6%97%b6%e5%8a%a0%e8%bd%bd) - [《优化之:贪婪加载》](https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd) diff --git a/工作单元.md b/工作单元.md index 19c677f..b68a574 100644 --- a/工作单元.md +++ b/工作单元.md @@ -5,7 +5,7 @@ UnitOfWork 可将多个仓储放在一个单元管理执行,最终通用 Commi var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + "Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10"; -IFreeSql fsql = new FreeSql.FreeSqlBuilder() +static IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, connstr) .UseAutoSyncStructure(true) //自动同步实体结构到数据库 .Build(); //请务必定义成 Singleton 单例模式 diff --git a/延时加载.md b/延时加载.md index 9210775..97dcc84 100644 --- a/延时加载.md +++ b/延时加载.md @@ -120,7 +120,6 @@ limit 0,1)) ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) - [《过滤器、全局过滤器》](https://github.com/2881099/FreeSql/wiki/%e8%bf%87%e6%bb%a4%e5%99%a8) diff --git a/性能.md b/性能.md index 01cafc5..e3494d8 100644 --- a/性能.md +++ b/性能.md @@ -208,7 +208,6 @@ public void QueryList() { - [《使用读写分离》](https://github.com/2881099/FreeSql/wiki/%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb) - [《分区、分表、分库》](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e5%8c%ba%e5%88%86%e8%a1%a8) - [《租户》](https://github.com/2881099/FreeSql/wiki/%e7%a7%9f%e6%88%b7) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) - [《过滤器、全局过滤器》](https://github.com/2881099/FreeSql/wiki/%e8%bf%87%e6%bb%a4%e5%99%a8) diff --git a/查询.md b/查询.md index a7b795e..8dfddcd 100644 --- a/查询.md +++ b/查询.md @@ -3,7 +3,6 @@ FreeSql在查询数据下足了功能,链式查询语法、多表查询、表 - [《分页查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e9%a1%b5%e6%9f%a5%e8%af%a2) - [《单表查询》](https://github.com/2881099/FreeSql/wiki/%e5%8d%95%e8%a1%a8%e6%9f%a5%e8%af%a2) - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《分组聚合查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e7%bb%84%e8%81%9a%e5%90%88%e6%9f%a5%e8%af%a2) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) diff --git a/添加.md b/添加.md index 173d7dd..feaf2ef 100644 --- a/添加.md +++ b/添加.md @@ -4,7 +4,7 @@ FreeSql 提供单条和批量插入数据的方法,在特定的数据库执行 var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + "Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10"; -IFreeSql fsql = new FreeSql.FreeSqlBuilder() +static IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, connstr) .UseAutoSyncStructure(true) //自动同步实体结构到数据库 .Build(); //请务必定义成 Singleton 单例模式 diff --git a/缓存.md b/缓存.md deleted file mode 100644 index 5a91ac5..0000000 --- a/缓存.md +++ /dev/null @@ -1,49 +0,0 @@ -FreeSql增加了缓存支持,可以快速将查询数据缓存起来,以便提升性能。 - -```csharp -IFreeSql fsql = new FreeSql.FreeSqlBuilder() - .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10") - .UseCache(null) //使用缓存,不指定默认使用内存 IDistributedCache - .Build(); //请务必定义成 Singleton 单例模式 - -[Table(Name = "tb_topic")] -class Topic { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TestTypeInfoGuid { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } -} - -ISelect select => fsql.Select(); - -var result1 = select.Where(a => 1 == 1).Caching(20, "testcaching").ToList(); //结果被缓存起来 -var testcaching1 = g.mysql.Cache.Get("testcaching"); //这里可以查看缓存的值 -Assert.NotNull(testcaching1); -var result2 = select.Where(a => 1 == 1).Caching(20, "testcaching").ToList(); //这次查询使用了缓存 -var testcaching2 = g.mysql.Cache.Get("testcaching"); -Assert.NotNull(testcaching2); -Assert.Equal(result1.Count, result1.Count); -``` - -## 参考资料 - -* [《CodeFirst模式开发介绍》](https://github.com/2881099/FreeSql/wiki/CodeFirst) - * [《CodeFirst模式之一:实体特性》](https://github.com/2881099/FreeSql/wiki/%e5%ae%9e%e4%bd%93%e7%89%b9%e6%80%a7) - * [《CodeFirst模式之二:FluentApi》](https://github.com/2881099/FreeSql/wiki/FluentApi) - * [《CodeFirst模式之三:自定义特性》](https://github.com/2881099/FreeSql/wiki/%e8%87%aa%e5%ae%9a%e4%b9%89%e7%89%b9%e6%80%a7) - * [《CodeFirst模式之四:类型映射》](https://github.com/2881099/FreeSql/wiki/%e7%b1%bb%e5%9e%8b%e6%98%a0%e5%b0%84) - * [《CodeFirst模式之五:迁移结构》](https://github.com/2881099/FreeSql/wiki/CodeFirst#%e8%bf%81%e7%a7%bb%e7%bb%93%e6%9e%84) -- [《DbFirst模式开发介绍》](https://github.com/2881099/FreeSql/wiki/DbFirst) -- [《使用读写分离》](https://github.com/2881099/FreeSql/wiki/%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb) -- [《分区、分表、分库》](https://github.com/2881099/FreeSql/wiki/%e5%88%86%e5%8c%ba%e5%88%86%e8%a1%a8) -- [《过滤器、全局过滤器》](https://github.com/2881099/FreeSql/wiki/%e8%bf%87%e6%bb%a4%e5%99%a8) -- [《租户》](https://github.com/2881099/FreeSql/wiki/%e7%a7%9f%e6%88%b7) - -## API -| 方法 | 返回值 | 参数 | 描述 | -| ------------- | - | - | - | -| ToList | List\ | | 执行SQL查询,返回 T1 实体所有字段的记录,若存在导航属性则一起查询返回,记录不存在时返回 Count 为 0 的列表 | -| 【其他】 | -| Caching | \ | int seconds, string key = null | 缓存查询结果 | \ No newline at end of file diff --git a/联级保存.md b/联级保存.md index 43157e7..46c5700 100644 --- a/联级保存.md +++ b/联级保存.md @@ -14,7 +14,7 @@ # 关闭联级保存功能 -全局关闭: +全局关闭(默认): ```csharp fsql.SetDbContextOptions(opt => opt.EnableAddOrUpdateNavigateList = false); @@ -26,7 +26,7 @@ var repo = fsql.GetRepository(); repo.DbContextOptions.EnableAddOrUpdateNavigateList = false; ``` -# SaveMany +# SaveMany(推荐使用) 保存实体的指定【一对多】、【多对多】导航属性,SaveMany 方法实现在 BaseRepository、DbContext。 diff --git a/表达式函数.md b/表达式函数.md index f0f29a6..28ab737 100644 --- a/表达式函数.md +++ b/表达式函数.md @@ -351,7 +351,6 @@ public static class DbFunc ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) diff --git a/贪婪加载.md b/贪婪加载.md index 9b859ea..27f9d1e 100644 --- a/贪婪加载.md +++ b/贪婪加载.md @@ -1,4 +1,4 @@ -## Dto 映射查询 +## 1、Dto 映射查询 ```csharp Select().Limit(10).ToList(a => new TestDto()); @@ -42,7 +42,7 @@ A, B, C 都有 id,Dto { id, a1, a2, b1, b2 },A.id 被映射。也可以指 > 友情提醒:在 dto 可以直接映射一个导航属性 -## 导航属性 ManyToOne/OneToOne +## 2、导航属性 ManyToOne/OneToOne ManyToOne/OneToOne 导航属性通过 ToList() 加载,这个方法有一个参数:includeNestedMembers。 @@ -67,7 +67,7 @@ Select().Where(a => a.Parent.Name == "1").ToList(); Select().Include(a => a.Parent).ToList(); ``` -## 导航属性 OneToMany/ManyToMany +## 3、导航属性 OneToMany/ManyToMany IncludeMany 贪婪加载集合的导航属性,其实是分两次查询,在 ToList 后进行了数据重装。 @@ -87,7 +87,7 @@ Select().IncludeMany(a => a.Songs, 然后,其实在 then 那里,还可以继续进行向下 Include/IncludeMany。只要你喜欢,向下 100 层都没问题。 -## 变异 +## 4、变异 变异的 IncludeMany,即使选择的不是导航属性,也可以贪婪加载。 @@ -109,7 +109,7 @@ Select().IncludeMany(a => a.TestManys.Take(10)); Select().IncludeMany(a => a.TestManys.Select(b => new TestMany { Title = b.Title ... })); ``` -## IncludeMany 扩展方法 +## 5、IncludeMany 扩展方法 前面介绍 ISelect 中进行贪婪加载集合属性数据,主数据与子数据查询必须在一个代码逻辑内完成。 @@ -121,7 +121,7 @@ new List(new[] { song1, song2, song3 }).IncludeMany(fsql, a => a.Tags); 这是一个扩展方法(IncludeMany),方法名与 ISelect.IncludeMany 同名,参数基本一致(除了需要额外传递 IFreeSql 对象参数),功能也一致(包括前面提到的变异)。 -## IncludeMany 两种方式对比 +## 6、IncludeMany 两种方式对比 方式一(IncludeMany 扩展方法): @@ -191,7 +191,6 @@ dto.IncludeMany(d => d.Vods.Take(10).Where(vod => vod.TypeId == d.TypeId)); ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository) diff --git a/过滤器.md b/过滤器.md index 70c38e4..85e8cc6 100644 --- a/过滤器.md +++ b/过滤器.md @@ -24,11 +24,13 @@ fsql.Select().DisableGlobalFilter().ToList(); //禁用所有 fsql.Update/Delete 方法效果同上。 -# 仓储过滤器 +# 仓储过滤器(早期功能,可跳过以下内容) -FreeSql.Repository 也同样实现了过滤器功能,它不仅在查询时过滤,删除/修改/插入篇还会进行验证数据,避免数据安全问题。 +FreeSql.Repository 也实现了过滤器功能,它在查询时过滤,删除/修改/插入篇还会进行验证数据,避免数据安全问题。 -> 注意:仓储的过滤器与 IFreeSql.GlobalFilter 不是一个功能,可以同时生效 +> 注意:仓储的过滤器与 IFreeSql.GlobalFilter 不是一个功能,可以同时生效。 + +> 推荐使用 IFreeSql.GlobalFilter。仓储过滤器在早期出的功能,会一直保留。 每个仓储实例都有 IDataFilter 属性,可利用其完成过滤器管理,它是独立的修改后不影响全局。 diff --git a/返回数据.md b/返回数据.md index 3465750..a458640 100644 --- a/返回数据.md +++ b/返回数据.md @@ -1,105 +1,55 @@ FreeSql 采用 ExpressionTree 优化读取速读,如果懂技术的你一定知道 .NETCore 技术下除了原生代码,最快就是 Emit 和 ExpressionTree。项目在初期使用的反射+缓存,虽然 .NETCore 优化了反射性能,但经过与Dapper性能测试对比之后,发现仍然有一定差距,改成 ExpresstionTree 后才与 Dapper 性能相当。FreeSql 支持的类型较多,实现 ExpressionTree 的复杂度较大,有兴趣的朋友可以翻阅源代码。 +## 1、返回单条记录 ```csharp -IFreeSql fsql = new FreeSql.FreeSqlBuilder() - .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10") - .Build(); //请务必定义成 Singleton 单例模式 - -[Table(Name = "tb_topic")] -class Topic { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TestTypeInfoGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } -} -class TestTypeInfo { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } -} -class TestTypeParentInfo { - public int Id { get; set; } - public string Name { get; set; } -} - -ISelect select => fsql.Select(); -``` - -## 返回单条记录 -```csharp -Topic t1 = select.Where(a => a.Id == 1).ToOne(); +Topic t1 = fsql.Select().ToOne(); ``` > FreeSql有一个约定,ToOne 永远返回 null 或 有数据的实体对象,ToList 永远返回非 null 的 List\<实体类型\> -## 返回 List +## 2、返回 List ```csharp -List t1 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList(); +List t1 = fsql.Select().ToList(); ``` -## 返回 List + 导航属性的数据 +## 3、返回 List + 导航属性的数据 ```csharp -List t2 = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).ToList(); +List t2 = fsql.Select().LeftJoin(a => a.Type.Id == a.TypeId).ToList(); //此时会返回普通字段 + 导航对象 Type 的数据 ``` -## 指定字段返回 +## 4、指定字段返回 ```csharp //返回一个字段 -List t3 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList(a => a.Id); +List t3 = fsql.Select().ToList(a => a.Id); //返回匿名类 -List<匿名类> t4 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList(a => new { a.Id, a.Title }); +List<匿名类> t4 = fsql.Select().ToList(a => new { a.Id, a.Title }); //返回元组 -List<(int, string)> t5 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList<(int, string)>("id, title"); +List<(int, string)> t5 = fsql.Select().ToList<(int, string)>("id, title"); //返回SQL字段 -List<匿名类> t6 = select.Where(a => a.Id > 0).Skip(100).Limit(200) - .ToList(a => new { - a.Id, - a.Title, - cstitle = "substr(a.title, 0, 2)", //将 substr(a.title, 0, 2) 作为查询字段 - csnow = Convert.ToDateTime("now()"), //将 now() 作为查询字段 - //奇思妙想:怎么查询开窗函数的结果 - }); - -//返回更为复杂的结构 -List<匿名类> t7 = select.From((s, b, c) => s - .InnerJoin(a => a.TypeGuid == b.Guid) - .LeftJoin(a => c.Id == b.ParentId) - .Where(a => b.Name != "xxx")).ToList((a, b, c) => new { - a.Id, - ccc = new { a.Id, a.Title }, - tp = a.Type, - tp2 = new { - a.Id, - tp2 = a.Type.Name - }, - tp3 = new { - a.Id, - tp33 = new { - a.Id - } - } - }); +List<匿名类> t6 = fsql.Select().ToList(a => new { + a.Id, + a.Title, + a.Type, //可以直接返回导航属性 Type + cstitle = "substr(a.title, 0, 2)", //将 substr(a.title, 0, 2) 作为查询字段 + csnow = Convert.ToDateTime("now()"), //将 now() 作为查询字段 + //奇思妙想:怎么查询开窗函数的结果 +}); //返回子查询的字段 -List<匿名类> t6 = select.Where(a => a.Id > 0).Skip(100).Limit(200) - .ToList(a => new { - a.Id, - count = fsql.Select().Count(), - max = fsql.Select().Max(b => b.Id), - min = fsql.Select().Min(b => b.Id), - name = fsql.Select<2>().First(b => b.name) - }); +List<匿名类> t6 = fsql.Select().ToList(a => new { + a.Id, + count = fsql.Select().Count(), + max = fsql.Select().Max(b => b.Id), + min = fsql.Select().Min(b => b.Id), + name = fsql.Select<2>().First(b => b.name) +}); ``` -### 执行SQL +### 5、执行SQL ```csharp class xxx { public int Id { get; set; } @@ -112,7 +62,7 @@ List<(int, string ,string)> t7 = fsql.Ado.Query<(int, string, string)>("select * List t9 = fsql.Ado.Query("select * from song"); ``` -## 巧用AsTable +## 6、巧用AsTable ```csharp var sql = fsql.Select() .AsTable((a, b) => "(select * from tb_topic where clicks > 10)") @@ -120,7 +70,7 @@ var sql = fsql.Select() ``` > v1.0.1 ISelect 增加 WithSql("select * from user ...") 功能快速代理此方法 -## ToChunk +## 7、ToChunk 执行查询,分块返回数据,可减少内存开销。比如读取10万条数据,每次返回100条处理。 ```csharp @@ -133,7 +83,7 @@ fsql.Select().OrderBy(a => a.Id).ToChunk(100, list => //这里示范,最终 testlist1 与 testlist2 返回的数据相同。 ``` -## Dto 映射查询 +## 8、Dto 映射查询 ```csharp Select().Limit(10).ToList(a => new TestDto()); @@ -177,7 +127,7 @@ A, B, C 都有 id,Dto { id, a1, a2, b1, b2 },A.id 被映射。也可以指 > 友情提醒:在 dto 可以直接映射一个导航属性 -## API +## 9、API | 方法 | 返回值 | 参数 | 描述 | | ------------- | - | - | - | @@ -196,7 +146,6 @@ A, B, C 都有 id,Dto { id, a1, a2, b1, b2 },A.id 被映射。也可以指 ## 参考资料 - [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2) -- [《利用导航属性查询》](https://github.com/2881099/FreeSql/wiki/%e5%88%a9%e7%94%a8%e5%af%bc%e8%88%aa%e5%b1%9e%e6%80%a7) - [《返回数据》](https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%95%b0%e6%8d%ae) - [《LinqToSql》](https://github.com/2881099/FreeSql/wiki/LinqToSql) - [《仓储层Repository》](https://github.com/2881099/FreeSql/wiki/Repository)