mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 12:33:44 +08:00
Update Subquery.ToList
This commit is contained in:
@@ -13,7 +13,7 @@ using System.Collections.ObjectModel;
|
||||
using NetTaste;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -1434,7 +1434,9 @@ namespace SqlSugar
|
||||
var ps = this.QueryBuilder.Parameters;
|
||||
var itemProperty = typeof(TResult).GetProperty(subPara.Key);
|
||||
var callType = itemProperty.PropertyType.GetGenericArguments()[0];
|
||||
var methodParamters = new object[] { subPara.Value.ObjToString().Replace("@sugarIndex", "0"), ps };
|
||||
var sql = subPara.Value.ObjToString().Replace("@sugarIndex", "0");
|
||||
sql =SqlBuilder.RemoveParentheses(sql);
|
||||
var methodParamters = new object[] { sql, ps };
|
||||
var subList = ExpressionBuilderHelper.CallFunc(callType, methodParamters, this.Clone(), "SubQueryList");
|
||||
for (var i = 0; i < result.Count; i++)
|
||||
{
|
||||
@@ -1472,6 +1474,10 @@ namespace SqlSugar
|
||||
};
|
||||
var value = UtilMethods.GetSqlString(config.DbType, "@p", p, true);
|
||||
sql = sql.Replace(re.Name, value);
|
||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.Sqlite)
|
||||
{
|
||||
sql =SqlBuilder.RemoveParentheses(sql);
|
||||
}
|
||||
}
|
||||
sql = sql.Replace("@sugarIndex", index + "");
|
||||
sqls.Add(sql);
|
||||
|
@@ -586,32 +586,7 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Get SQL Partial
|
||||
public string Offset { get; set; }
|
||||
public virtual string GetSelectValue
|
||||
{
|
||||
get
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (this.SelectValue == null || this.SelectValue is string)
|
||||
{
|
||||
result = GetSelectValueByString();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = GetSelectValueByExpression();
|
||||
}
|
||||
if (this.SelectType == ResolveExpressType.SelectMultiple)
|
||||
{
|
||||
this.SelectCacheKey = this.SelectCacheKey + string.Join("-", this._JoinQueryInfos.Select(it => it.TableName));
|
||||
}
|
||||
if (IsDistinct)
|
||||
{
|
||||
result = " DISTINCT " + result;
|
||||
}
|
||||
if (this.SubToListParameters!=null&& this.SubToListParameters.Any())
|
||||
protected string SubToListMethod(string result)
|
||||
{
|
||||
List<string> names = new List<string>();
|
||||
var allShortName = new List<string>();
|
||||
@@ -657,10 +632,42 @@ namespace SqlSugar
|
||||
this.AppendColumns = colums;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Get SQL Partial
|
||||
public string Offset { get; set; }
|
||||
public virtual string GetSelectValue
|
||||
{
|
||||
get
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (this.SelectValue == null || this.SelectValue is string)
|
||||
{
|
||||
result = GetSelectValueByString();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = GetSelectValueByExpression();
|
||||
}
|
||||
if (this.SelectType == ResolveExpressType.SelectMultiple)
|
||||
{
|
||||
this.SelectCacheKey = this.SelectCacheKey + string.Join("-", this._JoinQueryInfos.Select(it => it.TableName));
|
||||
}
|
||||
if (IsDistinct)
|
||||
{
|
||||
result = " DISTINCT " + result;
|
||||
}
|
||||
if (this.SubToListParameters!=null&& this.SubToListParameters.Any())
|
||||
{
|
||||
result = SubToListMethod(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string GetSelectValueByExpression()
|
||||
{
|
||||
var expression = this.SelectValue as Expression;
|
||||
|
@@ -389,6 +389,11 @@ namespace SqlSugar
|
||||
indexTree++;
|
||||
}
|
||||
|
||||
public virtual string RemoveParentheses(string sql)
|
||||
{
|
||||
return sql;
|
||||
}
|
||||
|
||||
private ConditionalCollections ToConditionalCollections(ConditionalTree item,ref int indexTree, List<SugarParameter> parameters)
|
||||
{
|
||||
List<KeyValuePair<WhereType, ConditionalModel>> list = new List<KeyValuePair<WhereType, ConditionalModel>>();
|
||||
|
@@ -43,5 +43,6 @@ namespace SqlSugar
|
||||
KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models, int beginIndex = 0);
|
||||
string GetUnionFomatSql(string sql);
|
||||
Type GetNullType(string tableName,string columnName);
|
||||
string RemoveParentheses(string sql);
|
||||
}
|
||||
}
|
||||
|
@@ -22,5 +22,14 @@ namespace SqlSugar
|
||||
return "select DATETIME('now') ";
|
||||
}
|
||||
}
|
||||
public override string RemoveParentheses(string sql)
|
||||
{
|
||||
if (sql.StartsWith("(") && sql.EndsWith(")"))
|
||||
{
|
||||
sql = sql.Substring(1, sql.Length - 2);
|
||||
}
|
||||
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using MySqlX.XDevAPI.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -93,6 +94,10 @@ namespace SqlSugar
|
||||
{
|
||||
reval = " DISTINCT " + reval;
|
||||
}
|
||||
if (this.SubToListParameters != null && this.SubToListParameters.Any())
|
||||
{
|
||||
reval = SubToListMethod(reval);
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user