mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-29 10:49:36 +08:00
Add SqlFunc.ListAll
This commit is contained in:
parent
f1ebc3d2fc
commit
790ecadee4
@ -900,6 +900,85 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public string ListAll(MethodCallExpressionModel model)
|
||||
{
|
||||
if (IsArrayAnyParameter(model))
|
||||
{
|
||||
return ListArrayAny(model);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (model.Args[0].MemberValue != null && (model.Args[0].MemberValue as IList).Count > 0)
|
||||
{
|
||||
sb.Append(" ( ");
|
||||
var listPar = model.Args[1].MemberValue as ListAnyParameter;
|
||||
foreach (var item in (model.Args[0].MemberValue as IList))
|
||||
{
|
||||
var sql = listPar.Sql;
|
||||
if (sb.Length > 3)
|
||||
{
|
||||
sb.Append("AND");
|
||||
}
|
||||
foreach (var columnInfo in listPar.Columns)
|
||||
{
|
||||
var replace = listPar.ConvetColumnFunc($"{listPar.Name}.{columnInfo.DbColumnName}");
|
||||
if (sql.Contains(replace))
|
||||
{
|
||||
var value = columnInfo.PropertyInfo.GetValue(item);
|
||||
var newValue = "null";
|
||||
if (value != null)
|
||||
{
|
||||
if (UtilMethods.IsNumber(columnInfo.UnderType.Name))
|
||||
{
|
||||
newValue = value.ToString();
|
||||
}
|
||||
else if (columnInfo.UnderType == SqlSugar.UtilConstants.GuidType)
|
||||
{
|
||||
newValue = ToGuid(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>()
|
||||
{
|
||||
new MethodCallExpressionArgs(){
|
||||
MemberValue=value.ToSqlValue(),
|
||||
MemberName=value.ToSqlValue()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (columnInfo.UnderType == SqlSugar.UtilConstants.DateType)
|
||||
{
|
||||
newValue = ToDate(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>()
|
||||
{
|
||||
new MethodCallExpressionArgs(){
|
||||
MemberValue=UtilMethods.GetConvertValue( value).ToSqlValue(),
|
||||
MemberName=UtilMethods.GetConvertValue( value).ToSqlValue()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
newValue = value.ToSqlValue();
|
||||
}
|
||||
}
|
||||
sql = sql.Replace(replace, newValue);
|
||||
}
|
||||
}
|
||||
sb.Append(sql);
|
||||
}
|
||||
sb.Append(" ) ");
|
||||
}
|
||||
var result = sb.ToString();
|
||||
if (result.IsNullOrEmpty())
|
||||
{
|
||||
return " 1=2 ";
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public virtual string GetTableWithDataBase(string dataBaseName,string tableName)
|
||||
{
|
||||
return $"{dataBaseName}.{tableName}";
|
||||
|
@ -111,6 +111,7 @@ namespace SqlSugar
|
||||
string CompareTo(MethodCallExpressionModel model);
|
||||
string SplitIn(MethodCallExpressionModel model);
|
||||
string ListAny(MethodCallExpressionModel model);
|
||||
string ListAll(MethodCallExpressionModel model);
|
||||
string GetTableWithDataBase(string databaseName,string tableName);
|
||||
string Modulo(MethodCallExpressionModel mode);
|
||||
string Like(MethodCallExpressionModel mode);
|
||||
|
@ -385,5 +385,9 @@ namespace SqlSugar
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static bool ListAll<T>(List<T> listConstant, Expression<Func<T, bool>> expression)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ namespace SqlSugar
|
||||
}
|
||||
model.Args.Add(argItem);
|
||||
}
|
||||
else if (name == "ListAny" && item is LambdaExpression)
|
||||
else if (name.IsIn("ListAny","ListAll") && item is LambdaExpression)
|
||||
{
|
||||
var sql = GetNewExpressionValue(item, ResolveExpressType.WhereMultiple);
|
||||
var lamExp = (item as LambdaExpression);
|
||||
|
Loading…
Reference in New Issue
Block a user