mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update Core
This commit is contained in:
parent
aebf163eb9
commit
0416ab88d4
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
Loading…
Reference in New Issue
Block a user