Update Subquery.ToList

This commit is contained in:
sunkaixuan
2022-12-03 23:43:19 +08:00
parent e274f4e0de
commit 865bbad050
6 changed files with 83 additions and 50 deletions

View File

@@ -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,9 +1434,11 @@ 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++)
for (var i = 0; i < result.Count; i++)
{
var item = result[i];
var setValue = Activator.CreateInstance(itemProperty.PropertyType, true) as IList;
@@ -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);

View File

@@ -586,36 +586,11 @@ 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>();
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())
{
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 + "."));
}
}
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)
{
@@ -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;

View File

@@ -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>>();

View File

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

View File

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

View File

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