mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Update Core
This commit is contained in:
parent
aebf163eb9
commit
0416ab88d4
@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -3,7 +3,6 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -958,16 +957,16 @@ namespace SqlSugar
|
|||||||
var parentIdName =UtilConvert.ToMemberExpression((parentIdExpression as LambdaExpression).Body).Member.Name;
|
var parentIdName =UtilConvert.ToMemberExpression((parentIdExpression as LambdaExpression).Body).Member.Name;
|
||||||
var ParentInfo = entity.Columns.First(it => it.PropertyName == parentIdName);
|
var ParentInfo = entity.Columns.First(it => it.PropertyName == parentIdName);
|
||||||
var parentPropertyName= ParentInfo.DbColumnName;
|
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)
|
if (current != null)
|
||||||
{
|
{
|
||||||
result.Add(current);
|
result.Add(current);
|
||||||
object parentId = ParentInfo.PropertyInfo.GetValue(current,null);
|
object parentId = ParentInfo.PropertyInfo.GetValue(current,null);
|
||||||
int i = 0;
|
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"));
|
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);
|
result.Add(parent);
|
||||||
parentId= ParentInfo.PropertyInfo.GetValue(parent, null);
|
parentId= ParentInfo.PropertyInfo.GetValue(parent, null);
|
||||||
++i;
|
++i;
|
||||||
@ -1177,11 +1176,16 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||||
{
|
{
|
||||||
InitMapping();
|
if (!QueryBuilder.IsClone)
|
||||||
ToSqlBefore();
|
{
|
||||||
string sql = QueryBuilder.ToSqlString();
|
var newQueryable = this.Clone();
|
||||||
RestoreMapping();
|
newQueryable.QueryBuilder.IsClone = true;
|
||||||
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
|
return newQueryable.ToSql();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _ToSql();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
|
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
|
||||||
{
|
{
|
||||||
@ -1464,6 +1468,14 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#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)
|
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;
|
var exp = (parentIdExpression as LambdaExpression).Body;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
@ -256,7 +255,7 @@ namespace SqlSugar
|
|||||||
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
|
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
|
||||||
};
|
};
|
||||||
resolveExpress.Resolve(expression, resolveType);
|
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 result = resolveExpress.Result;
|
||||||
var isSingleTableHasSubquery = IsSingle() && resolveExpress.SingleTableNameSubqueryShortName.HasValue();
|
var isSingleTableHasSubquery = IsSingle() && resolveExpress.SingleTableNameSubqueryShortName.HasValue();
|
||||||
if (isSingleTableHasSubquery)
|
if (isSingleTableHasSubquery)
|
||||||
@ -646,6 +645,10 @@ namespace SqlSugar
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region NoCopy
|
||||||
|
internal bool IsClone { get; set; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
private string GetTableName(string entityName)
|
private string GetTableName(string entityName)
|
||||||
{
|
{
|
||||||
if (this.AsTables != null && this.AsTables.Any(it=>it.Key==entityName))
|
if (this.AsTables != null && this.AsTables.Any(it=>it.Key==entityName))
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
Loading…
Reference in New Issue
Block a user