Update Queryable.In

This commit is contained in:
sunkaixuan 2023-07-21 13:32:16 +08:00
parent 4942842053
commit 03e9e23c50
2 changed files with 26 additions and 1 deletions

View File

@ -1004,8 +1004,21 @@ namespace SqlSugar
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
var propertyName = ExpressionTool.GetMemberName(expression);
var propertyColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == propertyName);
if (inValues?.Length==1&& inValues[0]?.GetType()?.FullName?.IsCollectionsList()==true && propertyColumn != null && propertyColumn?.UnderType?.FullName?.IsCollectionsList()!=true)
{
return In(fieldName, UtilMethods.ConvertToListOfObjects(inValues[0]));
}
else if (inValues?.Length == 1 && inValues[0]?.GetType()?.IsArray == true && propertyColumn != null && propertyColumn?.UnderType?.IsArray != true)
{
return In(fieldName, UtilMethods.ConvertToListOfObjects(inValues[0]));
}
else
{
return In(fieldName, inValues);
}
}
public virtual ISugarQueryable<T> In<TParamter>(List<TParamter> pkValues)
{
if (pkValues == null || pkValues.Count == 0)

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -17,6 +18,17 @@ namespace SqlSugar
{
public class UtilMethods
{
public static List<object> ConvertToListOfObjects(object inValues)
{
// 创建一个新的List<object>并逐个将元素转换并添加到其中
List<object> resultList = new List<object>();
foreach (var item in (IEnumerable)inValues )
{
resultList.Add(item);
}
return resultList;
}
public static bool IsValueTypeArray(object memberValue)
{
return memberValue is List<string> ||