mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 20:43:46 +08:00
Update Subquery.ToList
This commit is contained in:
@@ -13,7 +13,7 @@ using System.Collections.ObjectModel;
|
|||||||
using NetTaste;
|
using NetTaste;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
@@ -1434,9 +1434,11 @@ namespace SqlSugar
|
|||||||
var ps = this.QueryBuilder.Parameters;
|
var ps = this.QueryBuilder.Parameters;
|
||||||
var itemProperty = typeof(TResult).GetProperty(subPara.Key);
|
var itemProperty = typeof(TResult).GetProperty(subPara.Key);
|
||||||
var callType = itemProperty.PropertyType.GetGenericArguments()[0];
|
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");
|
var subList = ExpressionBuilderHelper.CallFunc(callType, methodParamters, this.Clone(), "SubQueryList");
|
||||||
for(var i=0;i<result.Count; i++)
|
for (var i = 0; i < result.Count; i++)
|
||||||
{
|
{
|
||||||
var item = result[i];
|
var item = result[i];
|
||||||
var setValue = Activator.CreateInstance(itemProperty.PropertyType, true) as IList;
|
var setValue = Activator.CreateInstance(itemProperty.PropertyType, true) as IList;
|
||||||
@@ -1472,6 +1474,10 @@ namespace SqlSugar
|
|||||||
};
|
};
|
||||||
var value = UtilMethods.GetSqlString(config.DbType, "@p", p, true);
|
var value = UtilMethods.GetSqlString(config.DbType, "@p", p, true);
|
||||||
sql = sql.Replace(re.Name, value);
|
sql = sql.Replace(re.Name, value);
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.Sqlite)
|
||||||
|
{
|
||||||
|
sql =SqlBuilder.RemoveParentheses(sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sql = sql.Replace("@sugarIndex", index + "");
|
sql = sql.Replace("@sugarIndex", index + "");
|
||||||
sqls.Add(sql);
|
sqls.Add(sql);
|
||||||
|
@@ -586,36 +586,11 @@ namespace SqlSugar
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
protected string SubToListMethod(string result)
|
||||||
|
|
||||||
#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())
|
|
||||||
{
|
{
|
||||||
List<string> names = new List<string>();
|
List<string> names = new List<string>();
|
||||||
var allShortName = new List<string>();
|
var allShortName = new List<string>();
|
||||||
allShortName.Add(this.Builder.SqlTranslationLeft+ Builder.GetNoTranslationColumnName(this.TableShortName.ObjToString().ToLower()+this.Builder.SqlTranslationRight+"."));
|
allShortName.Add(this.Builder.SqlTranslationLeft + Builder.GetNoTranslationColumnName(this.TableShortName.ObjToString().ToLower() + this.Builder.SqlTranslationRight + "."));
|
||||||
if (this.JoinQueryInfos.HasValue())
|
if (this.JoinQueryInfos.HasValue())
|
||||||
{
|
{
|
||||||
foreach (var item in this.JoinQueryInfos)
|
foreach (var item in this.JoinQueryInfos)
|
||||||
@@ -623,9 +598,9 @@ namespace SqlSugar
|
|||||||
allShortName.Add(this.Builder.SqlTranslationLeft + Builder.GetNoTranslationColumnName(item.ShortName.ObjToString().ToLower() + this.Builder.SqlTranslationRight + "."));
|
allShortName.Add(this.Builder.SqlTranslationLeft + Builder.GetNoTranslationColumnName(item.ShortName.ObjToString().ToLower() + this.Builder.SqlTranslationRight + "."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (this.EasyJoinInfos!=null&& this.EasyJoinInfos.Any())
|
else if (this.EasyJoinInfos != null && this.EasyJoinInfos.Any())
|
||||||
{
|
{
|
||||||
Check.ExceptionEasy("No Supprt Subquery.ToList(), Inner Join Or Left Join","Subquery.ToList请使用Inner方式联表");
|
Check.ExceptionEasy("No Supprt Subquery.ToList(), Inner Join Or Left Join", "Subquery.ToList请使用Inner方式联表");
|
||||||
}
|
}
|
||||||
if (this.TableShortName == null)
|
if (this.TableShortName == null)
|
||||||
{
|
{
|
||||||
@@ -657,10 +632,42 @@ namespace SqlSugar
|
|||||||
this.AppendColumns = colums;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string GetSelectValueByExpression()
|
public virtual string GetSelectValueByExpression()
|
||||||
{
|
{
|
||||||
var expression = this.SelectValue as Expression;
|
var expression = this.SelectValue as Expression;
|
||||||
|
@@ -389,6 +389,11 @@ namespace SqlSugar
|
|||||||
indexTree++;
|
indexTree++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string RemoveParentheses(string sql)
|
||||||
|
{
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
private ConditionalCollections ToConditionalCollections(ConditionalTree item,ref int indexTree, List<SugarParameter> parameters)
|
private ConditionalCollections ToConditionalCollections(ConditionalTree item,ref int indexTree, List<SugarParameter> parameters)
|
||||||
{
|
{
|
||||||
List<KeyValuePair<WhereType, ConditionalModel>> list = new List<KeyValuePair<WhereType, ConditionalModel>>();
|
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);
|
KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models, int beginIndex = 0);
|
||||||
string GetUnionFomatSql(string sql);
|
string GetUnionFomatSql(string sql);
|
||||||
Type GetNullType(string tableName,string columnName);
|
Type GetNullType(string tableName,string columnName);
|
||||||
|
string RemoveParentheses(string sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,5 +22,14 @@ namespace SqlSugar
|
|||||||
return "select DATETIME('now') ";
|
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;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
@@ -93,6 +94,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
reval = " DISTINCT " + reval;
|
reval = " DISTINCT " + reval;
|
||||||
}
|
}
|
||||||
|
if (this.SubToListParameters != null && this.SubToListParameters.Any())
|
||||||
|
{
|
||||||
|
reval = SubToListMethod(reval);
|
||||||
|
}
|
||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user