Update Core

This commit is contained in:
sunkaixuna 2021-08-03 22:02:55 +08:00
parent aebf163eb9
commit 0416ab88d4
7 changed files with 26 additions and 16 deletions

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;

View File

@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

View File

@ -2,7 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
@ -958,16 +957,16 @@ namespace SqlSugar
var parentIdName =UtilConvert.ToMemberExpression((parentIdExpression as LambdaExpression).Body).Member.Name;
var ParentInfo = entity.Columns.First(it => it.PropertyName == parentIdName);
var parentPropertyName= ParentInfo.DbColumnName;
var current = this.Context.Queryable<T>().InSingle(primaryKeyValue);
var current = this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingle(primaryKeyValue);
if (current != null)
{
result.Add(current);
object parentId = ParentInfo.PropertyInfo.GetValue(current,null);
int i = 0;
while (parentId!=null&&this.Context.Queryable<T>().In(parentId).Any())
while (parentId!=null&&this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).In(parentId).Any())
{
Check.Exception(i > 100, ErrorMessage.GetThrowMessage("Dead cycle", "出现死循环或超出循环上限100检查最顶层的ParentId是否是null或者0"));
var parent = this.Context.Queryable<T>().InSingle(parentId);
var parent = this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingle(parentId);
result.Add(parent);
parentId= ParentInfo.PropertyInfo.GetValue(parent, null);
++i;
@ -1177,11 +1176,16 @@ namespace SqlSugar
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
{
InitMapping();
ToSqlBefore();
string sql = QueryBuilder.ToSqlString();
RestoreMapping();
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
if (!QueryBuilder.IsClone)
{
var newQueryable = this.Clone();
newQueryable.QueryBuilder.IsClone = true;
return newQueryable.ToSql();
}
else
{
return _ToSql();
}
}
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
@ -1464,6 +1468,14 @@ namespace SqlSugar
#endregion
#region Private Methods
public virtual KeyValuePair<string, List<SugarParameter>> _ToSql()
{
InitMapping();
ToSqlBefore();
string sql = QueryBuilder.ToSqlString();
RestoreMapping();
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
}
private List<T> GetChildList(Expression<Func<T, object>> parentIdExpression, string pkName, List<T> list, object rootValue,bool isRoot=true)
{
var exp = (parentIdExpression as LambdaExpression).Body;

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
@ -256,7 +255,7 @@ namespace SqlSugar
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
};
resolveExpress.Resolve(expression, resolveType);
this.Parameters.AddRange(resolveExpress.Parameters.Select(it=>new SugarParameter(it.ParameterName, it.Value)));
this.Parameters.AddRange(resolveExpress.Parameters.Select(it => new SugarParameter(it.ParameterName, it.Value)));
var result = resolveExpress.Result;
var isSingleTableHasSubquery = IsSingle() && resolveExpress.SingleTableNameSubqueryShortName.HasValue();
if (isSingleTableHasSubquery)
@ -646,6 +645,10 @@ namespace SqlSugar
#endregion
#region NoCopy
internal bool IsClone { get; set; }
#endregion
private string GetTableName(string entityName)
{
if (this.AsTables != null && this.AsTables.Any(it=>it.Key==entityName))

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;