mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 增加 GlobalFilter.Apply before 参数将过滤条件插入 where 之前;#1566 #1492
This commit is contained in:
@ -4386,7 +4386,7 @@
|
||||
BigApple -> bigapple
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.Apply``1(System.String,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.Apply``1(System.String,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Boolean)">
|
||||
<summary>
|
||||
创建一个过滤器<para></para>
|
||||
提示:在 Lambda 中判断登陆身份,请参考资料 AsyncLocal
|
||||
@ -4394,9 +4394,10 @@
|
||||
<typeparam name="TEntity"></typeparam>
|
||||
<param name="name">名字</param>
|
||||
<param name="where">表达式</param>
|
||||
<param name="before">条件在最前面</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.ApplyIf``1(System.String,System.Func{System.Boolean},System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.ApplyIf``1(System.String,System.Func{System.Boolean},System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Boolean)">
|
||||
<summary>
|
||||
创建一个动态过滤器,当 condition 返回值为 true 时才生效<para></para>
|
||||
场景:当登陆身份是管理员,则过滤条件不生效<para></para>
|
||||
@ -4406,9 +4407,10 @@
|
||||
<param name="name">名字</param>
|
||||
<param name="condition">委托,返回值为 true 时才生效</param>
|
||||
<param name="where">表达式</param>
|
||||
<param name="before">条件在最前面</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.ApplyOnly``1(System.String,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.ApplyOnly``1(System.String,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Boolean)">
|
||||
<summary>
|
||||
创建一个过滤器(实体类型 属于指定 TEntity 才会生效)<para></para>
|
||||
提示:在 Lambda 中判断登陆身份,请参考资料 AsyncLocal
|
||||
@ -4416,9 +4418,10 @@
|
||||
<typeparam name="TEntity"></typeparam>
|
||||
<param name="name">名字</param>
|
||||
<param name="where">表达式</param>
|
||||
<param name="before">条件在最前面</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.ApplyOnlyIf``1(System.String,System.Func{System.Boolean},System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.ApplyOnlyIf``1(System.String,System.Func{System.Boolean},System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Boolean)">
|
||||
<summary>
|
||||
创建一个过滤器(实体类型 属于指定 TEntity 才会生效)<para></para>
|
||||
场景:当登陆身份是管理员,则过滤条件不生效<para></para>
|
||||
@ -4428,6 +4431,7 @@
|
||||
<param name="name">名字</param>
|
||||
<param name="condition">委托,返回值为 true 时才生效</param>
|
||||
<param name="where">表达式</param>
|
||||
<param name="before">条件在最前面</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.Model.AdoCommandFluent.WithConnection(System.Data.Common.DbConnection)">
|
||||
@ -6250,115 +6254,3 @@
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
`0})">
|
||||
<summary>
|
||||
插入数据,传入实体集合
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.InsertOrUpdate``1">
|
||||
<summary>
|
||||
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||
MySql 5.6+: on duplicate key update<para></para>
|
||||
PostgreSQL 9.4+: on conflict do update<para></para>
|
||||
SqlServer 2008+: merge into<para></para>
|
||||
Oracle 11+: merge into<para></para>
|
||||
Sqlite: replace into<para></para>
|
||||
达梦: merge into<para></para>
|
||||
人大金仓:on conflict do update<para></para>
|
||||
神通:merge into<para></para>
|
||||
MsAccess:不支持<para></para>
|
||||
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1">
|
||||
<summary>
|
||||
修改数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1(System.Object)">
|
||||
<summary>
|
||||
修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1">
|
||||
<summary>
|
||||
查询数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1(System.Object)">
|
||||
<summary>
|
||||
查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1">
|
||||
<summary>
|
||||
删除数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1(System.Object)">
|
||||
<summary>
|
||||
删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步)<para></para>
|
||||
v1.5.0 关闭了线程事务超时自动提交的机制
|
||||
</summary>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Data.IsolationLevel,System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步)<para></para>
|
||||
v1.5.0 关闭了线程事务超时自动提交的机制
|
||||
</summary>
|
||||
<param name="isolationLevel"></param>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Ado">
|
||||
<summary>
|
||||
数据库访问对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Aop">
|
||||
<summary>
|
||||
所有拦截方法都在这里
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.CodeFirst">
|
||||
<summary>
|
||||
CodeFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.DbFirst">
|
||||
<summary>
|
||||
DbFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.GlobalFilter">
|
||||
<summary>
|
||||
全局过滤设置,可默认附加为 Select/Update/Delete 条件
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -2361,7 +2361,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
|
||||
static ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>> _dicGetWhereCascadeSqlError = new ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>>();
|
||||
public string GetWhereCascadeSql(SelectTableInfo tb, List<GlobalFilter.Item> filters, bool isMultitb)
|
||||
public string GetWhereCascadeSql(SelectTableInfo tb, IEnumerable<GlobalFilter.Item> filters, bool isMultitb)
|
||||
{
|
||||
if (filters.Any())
|
||||
{
|
||||
|
@ -19,6 +19,7 @@ namespace FreeSql.Internal
|
||||
internal Func<bool> Condition { get; set; }
|
||||
public LambdaExpression Where { get; internal set; }
|
||||
public bool Only { get; internal set; }
|
||||
public bool Before { get; internal set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建一个过滤器<para></para>
|
||||
@ -27,8 +28,9 @@ namespace FreeSql.Internal
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <param name="name">名字</param>
|
||||
/// <param name="where">表达式</param>
|
||||
/// <param name="before">条件在最前面</param>
|
||||
/// <returns></returns>
|
||||
public GlobalFilter Apply<TEntity>(string name, Expression<Func<TEntity, bool>> where) => Apply(false, name, () => true, where);
|
||||
public GlobalFilter Apply<TEntity>(string name, Expression<Func<TEntity, bool>> where, bool before = false) => Apply(false, name, () => true, where, before);
|
||||
/// <summary>
|
||||
/// 创建一个动态过滤器,当 condition 返回值为 true 时才生效<para></para>
|
||||
/// 场景:当登陆身份是管理员,则过滤条件不生效<para></para>
|
||||
@ -38,8 +40,9 @@ namespace FreeSql.Internal
|
||||
/// <param name="name">名字</param>
|
||||
/// <param name="condition">委托,返回值为 true 时才生效</param>
|
||||
/// <param name="where">表达式</param>
|
||||
/// <param name="before">条件在最前面</param>
|
||||
/// <returns></returns>
|
||||
public GlobalFilter ApplyIf<TEntity>(string name, Func<bool> condition, Expression<Func<TEntity, bool>> where) => Apply(false, name, condition, where);
|
||||
public GlobalFilter ApplyIf<TEntity>(string name, Func<bool> condition, Expression<Func<TEntity, bool>> where, bool before = false) => Apply(false, name, condition, where, before);
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个过滤器(实体类型 属于指定 TEntity 才会生效)<para></para>
|
||||
@ -48,8 +51,9 @@ namespace FreeSql.Internal
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <param name="name">名字</param>
|
||||
/// <param name="where">表达式</param>
|
||||
/// <param name="before">条件在最前面</param>
|
||||
/// <returns></returns>
|
||||
public GlobalFilter ApplyOnly<TEntity>(string name, Expression<Func<TEntity, bool>> where) => Apply(true, name, () => true, where);
|
||||
public GlobalFilter ApplyOnly<TEntity>(string name, Expression<Func<TEntity, bool>> where, bool before = false) => Apply(true, name, () => true, where, before);
|
||||
/// <summary>
|
||||
/// 创建一个过滤器(实体类型 属于指定 TEntity 才会生效)<para></para>
|
||||
/// 场景:当登陆身份是管理员,则过滤条件不生效<para></para>
|
||||
@ -59,10 +63,11 @@ namespace FreeSql.Internal
|
||||
/// <param name="name">名字</param>
|
||||
/// <param name="condition">委托,返回值为 true 时才生效</param>
|
||||
/// <param name="where">表达式</param>
|
||||
/// <param name="before">条件在最前面</param>
|
||||
/// <returns></returns>
|
||||
public GlobalFilter ApplyOnlyIf<TEntity>(string name, Func<bool> condition, Expression<Func<TEntity, bool>> where) => Apply(true, name, condition, where);
|
||||
public GlobalFilter ApplyOnlyIf<TEntity>(string name, Func<bool> condition, Expression<Func<TEntity, bool>> where, bool before = false) => Apply(true, name, condition, where, before);
|
||||
|
||||
GlobalFilter Apply<TEntity>(bool only, string name, Func<bool> condition, Expression<Func<TEntity, bool>> where)
|
||||
GlobalFilter Apply<TEntity>(bool only, string name, Func<bool> condition, Expression<Func<TEntity, bool>> where, bool before)
|
||||
{
|
||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||
if (where == null) return this;
|
||||
@ -78,6 +83,7 @@ namespace FreeSql.Internal
|
||||
item.Where = newlambda;
|
||||
item.Condition = condition;
|
||||
item.Only = only;
|
||||
item.Before = before;
|
||||
_filters.AddOrUpdate(name, item, (_, __) => item);
|
||||
return this;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ namespace FreeSql.Internal.Model
|
||||
public SelectTableInfoType Type { get; set; }
|
||||
|
||||
public string Cascade { get; set; }
|
||||
public string CascadeBefore { get; set; }
|
||||
}
|
||||
public enum SelectTableInfoType { From, LeftJoin, InnerJoin, RightJoin, RawJoin, Parent }
|
||||
}
|
||||
|
Reference in New Issue
Block a user