mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-24 21:13:46 +08:00
-
This commit is contained in:
@@ -450,14 +450,14 @@ namespace SqlSugar
|
|||||||
{ "AddMilliseconds",DateType.Millisecond}
|
{ "AddMilliseconds",DateType.Millisecond}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static bool IsContainsArray(MethodCallExpression express, string methodName, bool isValidNativeMethod)
|
private bool IsContainsArray(MethodCallExpression express, string methodName, bool isValidNativeMethod)
|
||||||
{
|
{
|
||||||
return !isValidNativeMethod && express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic") && methodName == "Contains";
|
return !isValidNativeMethod && express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic") && methodName == "Contains";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsSubMethod(MethodCallExpression express, string methodName)
|
private bool IsSubMethod(MethodCallExpression express, string methodName)
|
||||||
{
|
{
|
||||||
return SubTools.SubItems.Any(it => it.Name == methodName) && express.Object != null && express.Object.Type.Name == "Subqueryable`1";
|
return SubTools.SubItems(this.Context).Any(it => it.Name == methodName) && express.Object != null && express.Object.Type.Name == "Subqueryable`1";
|
||||||
}
|
}
|
||||||
private void CheckMethod(MethodCallExpression expression)
|
private void CheckMethod(MethodCallExpression expression)
|
||||||
{
|
{
|
||||||
|
@@ -8,9 +8,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public interface ISubOperation
|
public interface ISubOperation
|
||||||
{
|
{
|
||||||
|
ExpressionContext Context { get; set; }
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
string GetValue(ExpressionContext context, Expression expression);
|
string GetValue(Expression expression);
|
||||||
int Sort { get; }
|
int Sort { get; }
|
||||||
Expression Expression { get; set; }
|
Expression Expression { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,12 +26,17 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
var argExp = exp.Arguments[0];
|
var argExp = exp.Arguments[0];
|
||||||
var result = "AND " + SubTools.GetMethodValue(context, argExp, ResolveExpressType.WhereMultiple);
|
var result = "AND " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.WhereMultiple);
|
||||||
var selfParameterName = context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
result = result.Replace(selfParameterName, string.Empty);
|
result = result.Replace(selfParameterName, string.Empty);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SubAny : ISubOperation
|
public class SubAny : ISubOperation
|
||||||
{
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
public Expression Expression
|
public Expression Expression
|
||||||
{
|
{
|
||||||
get;set;
|
get;set;
|
||||||
@@ -29,7 +34,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
return "EXISTS";
|
return "EXISTS";
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,12 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
return "SELECT";
|
return "SELECT";
|
||||||
}
|
}
|
||||||
|
@@ -28,12 +28,18 @@ namespace SqlSugar
|
|||||||
return 300;
|
return 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
var resType = exp.Method.ReturnType;
|
var resType = exp.Method.ReturnType;
|
||||||
var name = resType.GetGenericArguments().First().Name;
|
var name = resType.GetGenericArguments().First().Name;
|
||||||
return "FROM "+context.GetTranslationTableName(name, true);
|
return "FROM "+this.Context.GetTranslationTableName(name, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SubLeftBracket : ISubOperation
|
public class SubLeftBracket : ISubOperation
|
||||||
{
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
public Expression Expression
|
public Expression Expression
|
||||||
{
|
{
|
||||||
get;set;
|
get;set;
|
||||||
@@ -29,7 +34,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
return "(";
|
return "(";
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SubNotAny : ISubOperation
|
public class SubNotAny : ISubOperation
|
||||||
{
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
public Expression Expression
|
public Expression Expression
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
@@ -29,7 +34,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
return "NOT EXISTS";
|
return "NOT EXISTS";
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SubRightBracket : ISubOperation
|
public class SubRightBracket : ISubOperation
|
||||||
{
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
public Expression Expression
|
public Expression Expression
|
||||||
{
|
{
|
||||||
get;set;
|
get;set;
|
||||||
@@ -29,7 +34,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
return ")";
|
return ")";
|
||||||
}
|
}
|
||||||
|
@@ -30,10 +30,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression = null)
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression = null)
|
||||||
{
|
{
|
||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
return SubTools.GetMethodValue(context, exp.Arguments[0],ResolveExpressType.FieldSingle);
|
return SubTools.GetMethodValue(this.Context, exp.Arguments[0],ResolveExpressType.FieldSingle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SubSelectDefault : ISubOperation
|
public class SubSelectDefault : ISubOperation
|
||||||
{
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
public Expression Expression
|
public Expression Expression
|
||||||
{
|
{
|
||||||
get;set;
|
get;set;
|
||||||
@@ -28,7 +33,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
return "*";
|
return "*";
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubTop : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Top";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.Context is SqlServerExpressionContext)
|
||||||
|
{
|
||||||
|
return 150;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 450;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
if (this.Context is SqlServerExpressionContext)
|
||||||
|
{
|
||||||
|
return "TOP 1";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "limit 0,1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -26,12 +26,17 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetValue(ExpressionContext context, Expression expression)
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
{
|
{
|
||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
var argExp= exp.Arguments[0];
|
var argExp= exp.Arguments[0];
|
||||||
var result= "WHERE "+SubTools.GetMethodValue(context, argExp, ResolveExpressType.WhereMultiple);
|
var result= "WHERE "+SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);
|
||||||
var selfParameterName =context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name)+UtilConstants.Dot;
|
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name)+UtilConstants.Dot;
|
||||||
result = result.Replace(selfParameterName,string.Empty);
|
result = result.Replace(selfParameterName,string.Empty);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -52,19 +52,25 @@ namespace SqlSugar
|
|||||||
var isubList = this.allMethods.Select(exp =>
|
var isubList = this.allMethods.Select(exp =>
|
||||||
{
|
{
|
||||||
var methodName = exp.Method.Name;
|
var methodName = exp.Method.Name;
|
||||||
var item = SubTools.SubItems.First(s => s.Name == methodName);
|
var items = SubTools.SubItems(this.context);
|
||||||
|
var item = items.First(s => s.Name == methodName);
|
||||||
if (item is SubWhere && hasWhere == false)
|
if (item is SubWhere && hasWhere == false)
|
||||||
{
|
{
|
||||||
hasWhere = true;
|
hasWhere = true;
|
||||||
}
|
}
|
||||||
else if (item is SubWhere)
|
else if (item is SubWhere)
|
||||||
{
|
{
|
||||||
item = SubTools.SubItems.First(s => s is SubAnd);
|
item = items.First(s => s is SubAnd);
|
||||||
}
|
}
|
||||||
|
item.Context = this.context;
|
||||||
item.Expression = exp;
|
item.Expression = exp;
|
||||||
return item;
|
return item;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
isubList.Insert(0, new SubBegin());
|
isubList.Insert(0, new SubBegin());
|
||||||
|
if (isubList.Any(it => it is SubSelect))
|
||||||
|
{
|
||||||
|
isubList.Add(new SubTop() { Context=this.context });
|
||||||
|
}
|
||||||
if (isubList.Any(it => it is SubAny || it is SubNotAny))
|
if (isubList.Any(it => it is SubAny || it is SubNotAny))
|
||||||
{
|
{
|
||||||
isubList.Add(new SubLeftBracket());
|
isubList.Add(new SubLeftBracket());
|
||||||
@@ -74,7 +80,7 @@ namespace SqlSugar
|
|||||||
isubList = isubList.OrderBy(it => it.Sort).ToList();
|
isubList = isubList.OrderBy(it => it.Sort).ToList();
|
||||||
List<string> result = isubList.Select(it =>
|
List<string> result = isubList.Select(it =>
|
||||||
{
|
{
|
||||||
return it.GetValue(this.context, it.Expression);
|
return it.GetValue(it.Expression);
|
||||||
}).ToList();
|
}).ToList();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -8,16 +8,20 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SubTools
|
public class SubTools
|
||||||
{
|
{
|
||||||
public static List<ISubOperation> SubItems = new List<ISubOperation>()
|
public static List<ISubOperation> SubItems(ExpressionContext Context)
|
||||||
{
|
{
|
||||||
new SubSelect(),
|
|
||||||
new SubWhere(),
|
return new List<ISubOperation>()
|
||||||
new SubAnd(),
|
{
|
||||||
new SubAny(),
|
new SubSelect() { Context=Context },
|
||||||
new SubNotAny(),
|
new SubWhere(){ Context=Context },
|
||||||
new SubBegin(),
|
new SubAnd(){ Context=Context },
|
||||||
new SubFromTable()
|
new SubAny(){ Context=Context },
|
||||||
|
new SubNotAny(){ Context=Context },
|
||||||
|
new SubBegin(){ Context=Context },
|
||||||
|
new SubFromTable(){ Context=Context }
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetMethodValue(ExpressionContext context, Expression item, ResolveExpressType type)
|
public static string GetMethodValue(ExpressionContext context, Expression item, ResolveExpressType type)
|
||||||
{
|
{
|
||||||
|
@@ -82,6 +82,7 @@
|
|||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelect.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelect.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelectDefault.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelectDefault.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubNotAny.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubNotAny.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubTop.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Subquerable.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Subquerable.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWhere.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubWhere.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\SubResolve.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\SubResolve.cs" />
|
||||||
|
Reference in New Issue
Block a user