From 26f2578cf6fb58a69498a8ce77c06daeb4bae19f Mon Sep 17 00:00:00 2001
From: 2881099 <2881099@qq.com>
Date: Tue, 31 Aug 2021 10:59:39 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20IUnitOfWork.States=20?=
=?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86?=
=?UTF-8?q?=EF=BC=8C=E4=BE=BF=E4=BA=8E=E6=89=A9=E5=B1=95=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FreeSql.DbContext/FreeSql.DbContext.xml | 5 +
FreeSql.DbContext/UnitOfWork/IUnitOfWork.cs | 5 +
FreeSql.DbContext/UnitOfWork/UnitOfWork.cs | 2 +
.../UnitOfWork/UnitOfWorkManager.cs | 3 +
FreeSql/FreeSql.xml | 438 ++++++++++++------
5 files changed, 321 insertions(+), 132 deletions(-)
diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml
index 27909b2e..ea2308f8 100644
--- a/FreeSql.DbContext/FreeSql.DbContext.xml
+++ b/FreeSql.DbContext/FreeSql.DbContext.xml
@@ -365,6 +365,11 @@
工作单元内的实体变化跟踪
+
+
+ 自定义的状态数据
+
+
正在使用中的工作单元(调试)
diff --git a/FreeSql.DbContext/UnitOfWork/IUnitOfWork.cs b/FreeSql.DbContext/UnitOfWork/IUnitOfWork.cs
index 7f0565cd..b1527e17 100644
--- a/FreeSql.DbContext/UnitOfWork/IUnitOfWork.cs
+++ b/FreeSql.DbContext/UnitOfWork/IUnitOfWork.cs
@@ -32,5 +32,10 @@ namespace FreeSql
/// 工作单元内的实体变化跟踪
///
DbContext.EntityChangeReport EntityChangeReport { get; }
+
+ ///
+ /// 用户自定义的状态数据,便于扩展
+ ///
+ Dictionary States { get; }
}
}
diff --git a/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs b/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs
index 2480ac88..93643e24 100644
--- a/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs
+++ b/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs
@@ -164,6 +164,8 @@ namespace FreeSql
public DbContext.EntityChangeReport EntityChangeReport { get; } = new DbContext.EntityChangeReport();
+ public Dictionary States { get; } = new Dictionary();
+
~UnitOfWork() => this.Dispose();
int _disposeCounter;
public void Dispose()
diff --git a/FreeSql.DbContext/UnitOfWork/UnitOfWorkManager.cs b/FreeSql.DbContext/UnitOfWork/UnitOfWorkManager.cs
index ec9def63..42d7f2d3 100644
--- a/FreeSql.DbContext/UnitOfWork/UnitOfWorkManager.cs
+++ b/FreeSql.DbContext/UnitOfWork/UnitOfWorkManager.cs
@@ -188,6 +188,7 @@ namespace FreeSql
public IFreeSql Orm => _baseUow.Orm;
public IsolationLevel? IsolationLevel { get => _baseUow.IsolationLevel; set => _baseUow.IsolationLevel = value; }
public DbContext.EntityChangeReport EntityChangeReport => _baseUow.EntityChangeReport;
+ public Dictionary States => _baseUow.States;
public DbTransaction GetOrBeginTransaction(bool isCreate = true) => _baseUow.GetOrBeginTransaction(isCreate);
public void Commit() => _baseUow.Commit();
@@ -206,6 +207,7 @@ namespace FreeSql
public IFreeSql Orm => _baseUow.Orm;
public IsolationLevel? IsolationLevel { get => _baseUow.IsolationLevel; set { } }
public DbContext.EntityChangeReport EntityChangeReport => _baseUow.EntityChangeReport;
+ public Dictionary States => _baseUow.States;
public DbTransaction GetOrBeginTransaction(bool isCreate = true) => _baseUow.GetOrBeginTransaction(isCreate);
public void Commit() { }
@@ -220,6 +222,7 @@ namespace FreeSql
public IFreeSql Orm => _fsql;
public IsolationLevel? IsolationLevel { get; set; }
public DbContext.EntityChangeReport EntityChangeReport { get; } = new DbContext.EntityChangeReport();
+ public Dictionary States { get; } = new Dictionary();
public DbTransaction GetOrBeginTransaction(bool isCreate = true) => null;
public void Commit()
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index 06ac1dc3..23ce02ee 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -3172,6 +3172,177 @@
+
+
+ 测试数据库是否连接正确,本方法执行如下命令:
+ MySql/SqlServer/PostgreSQL/达梦/人大金仓/神通: SELECT 1
+ Oracle: SELECT 1 FROM dual
+
+ 命令超时设置(秒)
+
+ true: 成功, false: 失败
+
+
+
+ 查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
+
+
+
+
+
+
+
+
+
+ 查询,ExecuteReaderAsync(dr => {}, "select * from user where age > @age", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
+ 查询
+
+
+
+
+
+
+
+
+ 查询,ExecuteArrayAsync("select * from user where age > @age", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
+ 查询
+
+
+
+
+
+
+
+
+ 查询,ExecuteDataSetAsync("select * from user where age > @age; select 2", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
+ 查询
+
+
+
+
+
+
+
+
+ 查询,ExecuteDataTableAsync("select * from user where age > @age", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
+ 在【主库】执行
+
+
+
+
+
+
+
+
+ 在【主库】执行,ExecuteNonQueryAsync("delete from user where age > @age", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
+ 在【主库】执行
+
+
+
+
+
+
+
+
+ 在【主库】执行,ExecuteScalarAsync("select 1 from user where age > @age", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
+ 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new SqlParameter { ParameterName = "age", Value = 25 })
+
+
+
+
+
+
+
+
+
+
+ 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
+
+ 执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 })
+
+
+
+
+
+
+
+
+
+
+
+ 执行SQL返回对象集合,Query<User, Address>("select * from user where age > @age; select * from address", new { age = 25 })
+ 提示:parms 参数还可以传 Dictionary<string, object>
+
+
+
+
+
+
+
+
可自定义解析表达式
@@ -3411,192 +3582,183 @@
标识符,可将 CommandBefore 与 CommandAfter 进行匹配
+ column">
+
-
+
- 状态数据,可与 CommandAfter 共享
+ 获取c#值
+
+
+
+
+
+
+ 获取c#类型,int、long
+
+
+
+
+
+
+ 获取c#类型对象
+
+
+
+
+
+
+ 获取ado.net读取方法, GetBoolean、GetInt64
+
+
+
+
+
+
+ 序列化
+
+
+
+
+
+
+ 反序列化
+
+
+
+
+
+
+ 获取数据库枚举类型,适用 PostgreSQL
+
+
+
+
+
+
+ 临时 LambdaExpression.Parameter
-
+
- 发生的错误
+ 如果实体类有自增属性,分成两个 List,有值的Item1 merge,无值的Item2 insert
+
+
+
+
+
+
+ AsType, Ctor, ClearData 三处地方需要重新加载
-
+
- 执行SQL命令,返回的结果
+ AsType, Ctor, ClearData 三处地方需要重新加载
-
+
- 耗时(单位:Ticks)
+ 动态读取 DescriptionAttribute 注释文本
+
+
+
+
+
+
+ 通过属性的注释文本,通过 xml 读取
+
+
+ Dict:key=属性名,value=注释
+
+
+
+ 更新实体的元数据
-
+
- 耗时(单位:毫秒)
+ 执行更新的 SQL
-
+
- 标识符,可将 TraceBeforeEventArgs 与 TraceAfterEventArgs 进行匹配
+ 执行更新命令的参数
-
+
- 状态数据,可与 TraceAfter 共享
+ 执行更新命令影响的行
-
+
- 备注
+ 更新的实体数量
-
+
- 发生的错误
+ 更新的实体
-
+
- 耗时(单位:Ticks)
-
-
-
-
- 耗时(单位:毫秒)
-
-
-
-
- 【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
-
-
-
-
- 转小写同步结构,适用 PostgreSQL
-
-
-
-
- 转大写同步结构,适用 Oracle/达梦/人大金仓
-
-
-
-
- 将数据库的主键、自增、索引设置导入,适用 DbFirst 模式,无须在实体类型上设置 [Column(IsPrimary)] 或者 ConfigEntity。此功能目前可用于 mysql/sqlserver/postgresql/oracle。
- 本功能会影响 IFreeSql 首次访问的速度。
- 若使用 CodeFirst 创建索引后,又直接在数据库上建了索引,若无本功能下一次 CodeFirst 迁移时数据库上创建的索引将被删除
-
-
-
-
- 不使用命令参数化执行,针对 Insert/Update
-
-
-
-
- 是否生成命令参数化执行,针对 lambda 表达式解析
- 注意:常量不会参数化,变量才会做参数化
- var id = 100;
- fsql.Select<T>().Where(a => a.id == id) 会参数化
- fsql.Select<T>().Where(a => a.id == 100) 不会参数化
-
-
-
-
- 延时加载导航属性对象,导航属性需要声明 virtual
-
-
-
-
- 将实体类型与数据库对比,返回DDL语句
+ 创建一个过滤器
+ 提示:在 Lambda 中判断登陆身份,请参考资料 AsyncLocal
+ 名字
+ 表达式
-
+
- 将实体类型集合与数据库对比,返回DDL语句
-
- 实体类型
-
-
-
-
- 将实体类型与数据库对比,返回DDL语句(指定表名)
-
- 实体类型
- 指定表名对比
-
-
-
-
- 同步实体类型到数据库
- 注意:生产环境中谨慎使用
+ 创建一个动态过滤器,当 condition 返回值为 true 时才生效
+ 场景:当登陆身份是管理员,则过滤条件不生效
+ 提示:在 Lambda 中判断登陆身份,请参考资料 AsyncLocal
-
-
-
- 同步实体类型集合到数据库
- 注意:生产环境中谨慎使用
-
-
-
-
-
- 同步实体类型到数据库(指定表名)
- 注意:生产环境中谨慎使用
-
- 实体类型
- 指定表名对比
- 强制同步结构,无视缓存每次都同步
-
-
-
- 根据 System.Type 获取数据库信息
-
-
+ 名字
+ 委托,返回值为 true 时才生效
+ 表达式
-
+
- FreeSql FluentApi 配置实体,方法名与特性相同
+ 创建一个过滤器(实体类型 属于指定 TEntity 才会生效)
+ 提示:在 Lambda 中判断登陆身份,请参考资料 AsyncLocal
-
-
+
+ 名字
+ 表达式
-
+
- FreeSql FluentApi 配置实体,方法名与特性相同
+ 创建一个过滤器(实体类型 属于指定 TEntity 才会生效)
+ 场景:当登陆身份是管理员,则过滤条件不生效
+ 提示:在 Lambda 中判断登陆身份,请参考资料 AsyncLocal
-
-
+
+ 名字
+ 委托,返回值为 true 时才生效
+ 表达式
-
+
- 获取 FreeSql FluentApi 配置实体的元数据
+ 使用指定 DbConnection 连接执行
-
- 未使用ConfigEntity配置时,返回null
-
-
-
- 获取实体类核心配置
-
-
+
-
+
- 获取所有数据库
+ 使用指定 DbTransaction 事务执行
+
-
+
获取指定数据库的表信息,包括表、列详情、主键、唯一键、索引、外键、备注
@@ -4045,6 +4207,12 @@
超时
+
+
+ 获取资源
+
+
+
使用完毕后,归还资源
@@ -4115,6 +4283,12 @@
资源对象
+
+
+ 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象
+
+ 资源对象
+
归还对象给对象池的时候触发