Browse Source

Synchronization code

SqlSugar5
sunkaixuan 2 years ago
parent
commit
87d0e96bdb
  1. 2
      Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs
  2. 34
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 67
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubDistinctCount.cs
  4. 3
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs
  5. 5
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs
  6. 4
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

2
Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs

@ -308,6 +308,8 @@ namespace SqlSugar
column.IsIgnore = true;
column.NoSerialize = sugarColumn.NoSerialize;
column.ColumnDescription = sugarColumn.ColumnDescription;
column.IsJson = sugarColumn.IsJson;
column.IsArray = sugarColumn.IsArray;
}
}
if (column.ColumnDescription.IsNullOrEmpty()) column.ColumnDescription = GetPropertyAnnotation(result.Type, column.PropertyName);

34
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -1358,19 +1358,45 @@ namespace SqlSugar
var list= this.ToPivotList(columnSelector, rowSelector, dataSelector);
return this.Context.Utilities.SerializeObject(list);
}
public List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
public List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue,bool isContainOneself = true)
{
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var pk = GetTreeKey(entity);
var list = this.ToList();
return GetChildList(parentIdExpression, pk, list, primaryKeyValue);
if (isContainOneself)
{
var result= GetChildList(parentIdExpression, pk, list, primaryKeyValue);
var addItem = this.Context.Queryable<T>().In(pk, primaryKeyValue).First();
if (addItem != null)
{
result.Add(addItem);
}
return result;
}
else
{
return GetChildList(parentIdExpression, pk, list, primaryKeyValue);
}
}
public async Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
public async Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue,bool isContainOneself=true)
{
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var pk = GetTreeKey(entity);
var list = await this.ToListAsync();
return GetChildList(parentIdExpression,pk,list, primaryKeyValue);
if (isContainOneself)
{
var result = GetChildList(parentIdExpression, pk, list, primaryKeyValue);
var addItem = this.Context.Queryable<T>().In(pk, primaryKeyValue).First();
if (addItem != null)
{
result.Add(addItem);
}
return result;
}
else
{
return GetChildList(parentIdExpression, pk, list, primaryKeyValue);
}
}
public List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
{

67
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubDistinctCount.cs

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class SubDistinctCount : ISubOperation
{
public bool HasWhere
{
get; set;
}
public string Name
{
get
{
return "DistinctCount";
}
}
public Expression Expression
{
get; set;
}
public int Sort
{
get
{
return 200;
}
}
public ExpressionContext Context
{
get; set;
}
public string GetValue(Expression expression = null)
{
var exp = expression as MethodCallExpression;
var argExp = exp.Arguments[0];
var parametres = (argExp as LambdaExpression).Parameters;
if ((argExp as LambdaExpression).Body is UnaryExpression)
{
argExp = ((argExp as LambdaExpression).Body as UnaryExpression).Operand;
}
var argLambda = argExp as LambdaExpression;
if (this.Context.InitMappingInfo != null && argLambda != null && argLambda.Parameters.Count > 0)
{
foreach (var item in argLambda.Parameters)
{
this.Context.InitMappingInfo(item.Type);
}
this.Context.RefreshMapping();
}
var result = "COUNT(DISTINCT " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")";
var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot;
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
return result;
}
}
}

3
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs

@ -36,7 +36,8 @@ namespace SqlSugar
new SubHaving(){ Context=Context},
new SubWithNolock(){ Context=Context },
new SubEnableTableFilter(){ Context=Context },
new SubSelectStringJoin{ Context=Context }
new SubSelectStringJoin{ Context=Context },
new SubDistinctCount{ Context=Context }
};
}

5
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs

@ -120,6 +120,11 @@ namespace SqlSugar
{
return default(string);
}
public int DistinctCount(Func<T, object> expression)
{
return default(int);
}
public TResult Sum<TResult>(Func<T, TResult> expression) where TResult : struct
{
return default(TResult);

4
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -172,8 +172,8 @@ namespace SqlSugar
Task<string> ToJsonPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
KeyValuePair<string, List<SugarParameter>> ToSql();
string ToSqlString();
List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
List<T> ToChildList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true);
Task<List<T>> ToChildListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true);
List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
Task<List<T>> ToParentListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
List<T> ToTree(Expression<Func<T,IEnumerable<object>>> childListExpression, Expression<Func<T,object>> parentIdExpression,object rootValue);

Loading…
Cancel
Save