mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-17 21:49:33 +08:00
Add : SqlFunc.Subqueryable<Order>().DistinctCount(z=>z.Id)
This commit is contained in:
parent
73a19f8911
commit
f3a1c71ba1
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,8 @@ namespace SqlSugar
|
|||||||
new SubHaving(){ Context=Context},
|
new SubHaving(){ Context=Context},
|
||||||
new SubWithNolock(){ Context=Context },
|
new SubWithNolock(){ Context=Context },
|
||||||
new SubEnableTableFilter(){ Context=Context },
|
new SubEnableTableFilter(){ Context=Context },
|
||||||
new SubSelectStringJoin{ Context=Context }
|
new SubSelectStringJoin{ Context=Context },
|
||||||
|
new SubDistinctCount{ Context=Context }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +120,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return default(string);
|
return default(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int DistinctCount(Func<T, object> expression)
|
||||||
|
{
|
||||||
|
return default(int);
|
||||||
|
}
|
||||||
public TResult Sum<TResult>(Func<T, TResult> expression) where TResult : struct
|
public TResult Sum<TResult>(Func<T, TResult> expression) where TResult : struct
|
||||||
{
|
{
|
||||||
return default(TResult);
|
return default(TResult);
|
||||||
|
@ -127,6 +127,7 @@
|
|||||||
<Compile Include="Entities\DeleteNavOptions.cs" />
|
<Compile Include="Entities\DeleteNavOptions.cs" />
|
||||||
<Compile Include="Entities\JoinInfoParameter.cs" />
|
<Compile Include="Entities\JoinInfoParameter.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Common\NewExpressionInfo.cs" />
|
<Compile Include="ExpressionsToSql\Common\NewExpressionInfo.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubDistinctCount.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelectStringJoin.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelectStringJoin.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWithNoLock.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubWithNoLock.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubEnableTableFilter.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubEnableTableFilter.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user