mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-17 19:37:34 +08:00
Subquery support table filter
Subquery support nolock
This commit is contained in:
parent
3ed4e7d9f1
commit
4a40147d85
@ -108,6 +108,7 @@ namespace SqlSugar
|
|||||||
public virtual string SqlTranslationRight { get { return "]"; } }
|
public virtual string SqlTranslationRight { get { return "]"; } }
|
||||||
public virtual Action<Type> InitMappingInfo { get; set; }
|
public virtual Action<Type> InitMappingInfo { get; set; }
|
||||||
public virtual Action RefreshMapping { get; set; }
|
public virtual Action RefreshMapping { get; set; }
|
||||||
|
public virtual Type SubTableType { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Core methods
|
#region Core methods
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubEnableTableFilter : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasWhere
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "EnableTableFilter";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 402;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
var result = "";
|
||||||
|
if (this.Context.SugarContext != null)
|
||||||
|
{
|
||||||
|
var db = this.Context.SugarContext.Context;
|
||||||
|
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
|
||||||
|
Type type = this.Context.SubTableType;
|
||||||
|
var isWhere = HasWhere;
|
||||||
|
if (db.QueryFilter.GeFilterList != null) {
|
||||||
|
foreach (var item in db.QueryFilter.GeFilterList)
|
||||||
|
{
|
||||||
|
PropertyInfo field = item.GetType().GetProperty("exp", flag);
|
||||||
|
if (field != null)
|
||||||
|
{
|
||||||
|
Type ChildType = item.GetType().GetProperty("type", flag).GetValue(item, null) as Type;
|
||||||
|
if (ChildType == type)
|
||||||
|
{
|
||||||
|
var entityInfo = db.EntityMaintenance.GetEntityInfo(ChildType);
|
||||||
|
var exp = field.GetValue(item, null) as Expression;
|
||||||
|
var whereStr = isWhere ? " AND " : " WHERE ";
|
||||||
|
isWhere = true;
|
||||||
|
result += (whereStr + SubTools.GetMethodValue(Context, exp, ResolveExpressType.WhereSingle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,7 @@ namespace SqlSugar
|
|||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
var resType = exp.Method.ReturnType;
|
var resType = exp.Method.ReturnType;
|
||||||
var entityType = resType.GetGenericArguments().First();
|
var entityType = resType.GetGenericArguments().First();
|
||||||
|
this.Context.SubTableType = entityType;
|
||||||
var name = entityType.Name;
|
var name = entityType.Name;
|
||||||
if (this.Context.InitMappingInfo != null)
|
if (this.Context.InitMappingInfo != null)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubWithNolock : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasWhere
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "WithNoLock";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 301;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
if (Context is SqlServerExpressionContext)
|
||||||
|
{
|
||||||
|
return SqlWith.NoLock;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -33,7 +33,9 @@ namespace SqlSugar
|
|||||||
new SubOrderByDesc(){ Context=Context },
|
new SubOrderByDesc(){ Context=Context },
|
||||||
new SubGroupBy(){ Context=Context},
|
new SubGroupBy(){ Context=Context},
|
||||||
new SubAs(){Context=Context},
|
new SubAs(){Context=Context},
|
||||||
new SubHaving(){ Context=Context}
|
new SubHaving(){ Context=Context},
|
||||||
|
new SubWithNolock(){ Context=Context },
|
||||||
|
new SubEnableTableFilter(){ Context=Context }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,5 +151,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return default(int);
|
return default(int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Subqueryable<T> WithNoLock()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public Subqueryable<T> EnableTableFilter()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,8 @@
|
|||||||
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
|
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
|
||||||
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.cs" />
|
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.cs" />
|
||||||
<Compile Include="Entities\DbFastestProperties.cs" />
|
<Compile Include="Entities\DbFastestProperties.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubWithNoLock.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubEnableTableFilter.cs" />
|
||||||
<Compile Include="Json2Sql\Entities\JsonDeleteResult.cs" />
|
<Compile Include="Json2Sql\Entities\JsonDeleteResult.cs" />
|
||||||
<Compile Include="Json2Sql\Entities\JsonInsertResult.cs" />
|
<Compile Include="Json2Sql\Entities\JsonInsertResult.cs" />
|
||||||
<Compile Include="Json2Sql\Entities\JsonQueryResult.cs" />
|
<Compile Include="Json2Sql\Entities\JsonQueryResult.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user