Subquery support table filter

Subquery support   nolock
This commit is contained in:
sunkaixuan 2022-06-25 23:25:57 +08:00
parent 3ed4e7d9f1
commit 4a40147d85
7 changed files with 144 additions and 1 deletions

View File

@ -108,6 +108,7 @@ namespace SqlSugar
public virtual string SqlTranslationRight { get { return "]"; } }
public virtual Action<Type> InitMappingInfo { get; set; }
public virtual Action RefreshMapping { get; set; }
public virtual Type SubTableType { get; set; }
#endregion
#region Core methods

View File

@ -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;
}
}
}

View File

@ -44,6 +44,7 @@ namespace SqlSugar
var exp = expression as MethodCallExpression;
var resType = exp.Method.ReturnType;
var entityType = resType.GetGenericArguments().First();
this.Context.SubTableType = entityType;
var name = entityType.Name;
if (this.Context.InitMappingInfo != null)
{

View File

@ -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 "";
}
}
}
}

View File

@ -33,7 +33,9 @@ namespace SqlSugar
new SubOrderByDesc(){ Context=Context },
new SubGroupBy(){ Context=Context},
new SubAs(){Context=Context},
new SubHaving(){ Context=Context}
new SubHaving(){ Context=Context},
new SubWithNolock(){ Context=Context },
new SubEnableTableFilter(){ Context=Context }
};
}

View File

@ -151,5 +151,14 @@ namespace SqlSugar
{
return default(int);
}
public Subqueryable<T> WithNoLock()
{
return this;
}
public Subqueryable<T> EnableTableFilter()
{
return this;
}
}
}

View File

@ -104,6 +104,8 @@
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.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\JsonInsertResult.cs" />
<Compile Include="Json2Sql\Entities\JsonQueryResult.cs" />