From 9e9891ded45dfa5a8f14e33ef63bff38c84c31ba Mon Sep 17 00:00:00 2001
From: 28810 <28810@YEXIANGQIN>
Date: Wed, 2 Sep 2020 18:29:42 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20IUpdate/IDelete=20Wher?=
=?UTF-8?q?eIf=20=E6=96=B9=E6=B3=95=20#466=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FreeSql/FreeSql.xml | 383 ++++++++++--------
FreeSql/Interface/Curd/IDelete.cs | 8 +
FreeSql/Interface/Curd/IUpdate.cs | 8 +
.../Internal/CommonProvider/DeleteProvider.cs | 7 +-
.../Internal/CommonProvider/UpdateProvider.cs | 7 +-
5 files changed, 235 insertions(+), 178 deletions(-)
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index a7b0965c..0c309880 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -1260,6 +1260,15 @@
lambda表达式条件
+
+
+ lambda表达式条件,仅支持实体基础成员(不包含导航对象)
+ 若想使用导航对象,请使用 ISelect.ToUpdate() 方法
+
+ true 时生效
+ lambda表达式条件
+
+
原生sql语法条件,Where("id = ?id", new { id = 1 })
@@ -2670,6 +2679,15 @@
lambda表达式条件
+
+
+ lambda表达式条件,仅支持实体基础成员(不包含导航对象)
+ 若想使用导航对象,请使用 ISelect.ToUpdate() 方法
+
+ true 时生效
+ lambda表达式条件
+
+
原生sql语法条件,Where("id = ?id", new { id = 1 })
@@ -3311,182 +3329,7 @@
-
- 获取 Index 对应的值,也可以设置拦截的新值
-
-
-
-
- 标识符,可将 CommandBefore 与 CommandAfter 进行匹配
-
-
-
-
- 发生的错误
-
-
-
-
- 执行SQL命令,返回的结果
-
-
-
-
- 耗时(单位:Ticks)
-
-
-
-
- 耗时(单位:毫秒)
-
-
-
-
- 标识符,可将 TraceBeforeEventArgs 与 TraceAfterEventArgs 进行匹配
-
-
-
-
- 备注
-
-
-
-
- 发生的错误
-
-
-
-
- 耗时(单位: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语句
-
-
-
-
-
-
- 将实体类型集合与数据库对比,返回DDL语句
-
- 实体类型
-
-
-
-
- 将实体类型与数据库对比,返回DDL语句(指定表名)
-
- 实体类型
- 指定表名对比
-
-
-
-
- 同步实体类型到数据库
- 注意:生产环境中谨慎使用
-
-
-
-
-
- 同步实体类型集合到数据库
- 注意:生产环境中谨慎使用
-
-
-
-
-
- 同步实体类型到数据库(指定表名)
- 注意:生产环境中谨慎使用
-
- 实体类型
- 指定表名对比
- 强制同步结构,无视缓存每次都同步
-
-
-
- 根据 System.Type 获取数据库信息
-
-
-
-
-
-
- FreeSql FluentApi 配置实体,方法名与特性相同
-
-
-
-
-
-
-
- FreeSql FluentApi 配置实体,方法名与特性相同
-
-
-
-
-
-
-
- 获取 FreeSql FluentApi 配置实体的元数据
-
-
- 未使用ConfigEntity配置时,返回null
-
-
-
- 获取实体类核心配置
-
-
-
+
@@ -3678,6 +3521,194 @@
+
+
+ 设置 obj.CsName 属性值
+
+
+
+ 获取指定数据库的表信息,包括表、列详情、主键、唯一键、索引、外键、备注
+
+
+
+
+
+
+ 获取指定单表信息,包括列详情、主键、唯一键、索引、备注
+
+ 表名,如:dbo.table1
+ 是否忽略大小写
+
+
+
+
+ 判断表是否存在
+
+ 表名,如:dbo.table1
+ 是否忽略大小写
+
+
+
+
+ 获取数据库枚举类型int值
+
+
+
+
+
+
+ 获取c#转换,(int)、(long)
+
+
+
+
+
+
+ 获取c#值
+
+
+
+
+
+
+ 获取c#类型,int、long
+
+
+
+
+
+
+ 获取c#类型对象
+
+
+
+
+
+
+ 获取ado.net读取方法, GetBoolean、GetInt64
+
+
+
+
+
+
+ 序列化
+
+
+
+
+
+
+ 反序列化
+
+
+
+
+
+
+ 获取数据库枚举类型,适用 PostgreSQL
+
+
+
+
+
+
+ 如果实体类有自增属性,分成两个 List,有值的Item1 merge,无值的Item2 insert
+
+
+
+
+
+
+ AsType, Ctor, ClearData 三处地方需要重新加载
+
+
+
+
+ AsType, Ctor, ClearData 三处地方需要重新加载
+
+
+
+
+ 动态读取 DescriptionAttribute 注释文本
+
+
+
+
+
+
+ 通过属性的注释文本,通过 xml 读取
+
+
+ Dict:key=属性名,value=注释
+
+
+
+ 更新实体的元数据
+
+
+
+
+ 执行更新的 SQL
+
+
+
+
+ 执行更新命令的参数
+
+
+
+
+ 执行更新命令影响的行
+
+
+
+
+ 更新的实体数量
+
+
+
+
+ 更新的实体
+
+
+
+
+ 创建一个过滤器
+
+
+ 名字
+ 表达式
+
+
+
+
+ 当前操作的数据
+
+
+
+
+ 当前批次
+
+
+
+
+ 总批次数量
+
+
+
+
+ 获取 obj.CsName 属性值 MapType 之后的数据库值
+
+
+
+
+
+
+ 获取 obj.CsName 属性原始值(不经过 MapType)
+
+
+
设置 obj.CsName 属性值
diff --git a/FreeSql/Interface/Curd/IDelete.cs b/FreeSql/Interface/Curd/IDelete.cs
index 0edfd394..09515f8a 100644
--- a/FreeSql/Interface/Curd/IDelete.cs
+++ b/FreeSql/Interface/Curd/IDelete.cs
@@ -30,6 +30,14 @@ namespace FreeSql
///
IDelete Where(Expression> exp);
///
+ /// lambda表达式条件,仅支持实体基础成员(不包含导航对象)
+ /// 若想使用导航对象,请使用 ISelect.ToUpdate() 方法
+ ///
+ /// true 时生效
+ /// lambda表达式条件
+ ///
+ IDelete WhereIf(bool condition, Expression> exp);
+ ///
/// 原生sql语法条件,Where("id = ?id", new { id = 1 })
/// 提示:parms 参数还可以传 Dictionary<string, object>
///
diff --git a/FreeSql/Interface/Curd/IUpdate.cs b/FreeSql/Interface/Curd/IUpdate.cs
index 2abbdf64..49acf355 100644
--- a/FreeSql/Interface/Curd/IUpdate.cs
+++ b/FreeSql/Interface/Curd/IUpdate.cs
@@ -170,6 +170,14 @@ namespace FreeSql
///
IUpdate Where(Expression> exp);
///
+ /// lambda表达式条件,仅支持实体基础成员(不包含导航对象)
+ /// 若想使用导航对象,请使用 ISelect.ToUpdate() 方法
+ ///
+ /// true 时生效
+ /// lambda表达式条件
+ ///
+ IUpdate WhereIf(bool condition, Expression> exp);
+ ///
/// 原生sql语法条件,Where("id = ?id", new { id = 1 })
/// 提示:parms 参数还可以传 Dictionary<string, object>
///
diff --git a/FreeSql/Internal/CommonProvider/DeleteProvider.cs b/FreeSql/Internal/CommonProvider/DeleteProvider.cs
index 5e28e3a9..56b21f5a 100644
--- a/FreeSql/Internal/CommonProvider/DeleteProvider.cs
+++ b/FreeSql/Internal/CommonProvider/DeleteProvider.cs
@@ -86,7 +86,12 @@ namespace FreeSql.Internal.CommonProvider
}
public abstract List ExecuteDeleted();
- public IDelete Where(Expression> exp) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null, _params));
+ public IDelete Where(Expression> exp) => WhereIf(true, exp);
+ public IDelete WhereIf(bool condition, Expression> exp)
+ {
+ if (condition == false || exp == null) return this;
+ return this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null, _params));
+ }
public IDelete Where(string sql, object parms = null)
{
if (string.IsNullOrEmpty(sql)) return this;
diff --git a/FreeSql/Internal/CommonProvider/UpdateProvider.cs b/FreeSql/Internal/CommonProvider/UpdateProvider.cs
index 63a46ea0..b6a24926 100644
--- a/FreeSql/Internal/CommonProvider/UpdateProvider.cs
+++ b/FreeSql/Internal/CommonProvider/UpdateProvider.cs
@@ -519,7 +519,12 @@ namespace FreeSql.Internal.CommonProvider
return this;
}
- public IUpdate Where(Expression> expression) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, expression?.Body, null, _params));
+ public IUpdate Where(Expression> exp) => WhereIf(true, exp);
+ public IUpdate WhereIf(bool condition, Expression> exp)
+ {
+ if (condition == false || exp == null) return this;
+ return this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null, _params));
+ }
public IUpdate Where(string sql, object parms = null)
{
if (string.IsNullOrEmpty(sql)) return this;