Synchronization code

This commit is contained in:
sunkaixuan
2022-10-10 09:20:23 +08:00
parent 0638af8cdc
commit 87d0e96bdb
6 changed files with 108 additions and 7 deletions

View File

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

View File

@@ -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)
{

View File

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

View File

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

View File

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

View File

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