mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Update mongodb
This commit is contained in:
@@ -260,7 +260,6 @@ namespace SqlSugar.MongoDb
|
|||||||
name = "ToDate";
|
name = "ToDate";
|
||||||
if (name == "Contains" && methodCallExpression.Arguments.Count == 1
|
if (name == "Contains" && methodCallExpression.Arguments.Count == 1
|
||||||
&& methodCallExpression?.Object?.Type != null
|
&& methodCallExpression?.Object?.Type != null
|
||||||
&& ExpressionTool.GetParameters(methodCallExpression.Object).Count == 0
|
|
||||||
&& typeof(IEnumerable).IsAssignableFrom(methodCallExpression.Object.Type))
|
&& typeof(IEnumerable).IsAssignableFrom(methodCallExpression.Object.Type))
|
||||||
{
|
{
|
||||||
name = "ContainsArray";
|
name = "ContainsArray";
|
||||||
|
@@ -701,8 +701,12 @@ namespace SqlSugar.MongoDb
|
|||||||
// 获取字段名
|
// 获取字段名
|
||||||
BsonValue fieldName = new ExpressionVisitor(context).Visit(itemExp);
|
BsonValue fieldName = new ExpressionVisitor(context).Visit(itemExp);
|
||||||
|
|
||||||
|
var isConstValue = ExpressionTool.GetParameters(arrayExp).Count == 0;
|
||||||
// 获取数组值
|
// 获取数组值
|
||||||
var arrayObj = ExpressionTool.DynamicInvoke(arrayExp) as IEnumerable;
|
IEnumerable arrayObj = null;
|
||||||
|
if (isConstValue)
|
||||||
|
{
|
||||||
|
arrayObj = ExpressionTool.DynamicInvoke(arrayExp) as IEnumerable;
|
||||||
if (arrayObj == null)
|
if (arrayObj == null)
|
||||||
return null;
|
return null;
|
||||||
var name = fieldName.ToString();
|
var name = fieldName.ToString();
|
||||||
@@ -732,6 +736,19 @@ namespace SqlSugar.MongoDb
|
|||||||
var inDoc = new BsonDocument(name, new BsonDocument("$in", bsonArray));
|
var inDoc = new BsonDocument(name, new BsonDocument("$in", bsonArray));
|
||||||
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
|
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 数组表达式不是常量,需生成MongoDB $in表达式,数组字段为arrayExp,判断itemExp是否在数组中
|
||||||
|
// 获取字段名
|
||||||
|
var name = fieldName.ToString();
|
||||||
|
// 获取数组字段名
|
||||||
|
BsonValue arrayField = new ExpressionVisitor(context).Visit(arrayExp);
|
||||||
|
// 构建MongoDB的 $in 查询表达式,格式为 { "$in": [ "$_id", "$$let_RoleIds" ] }
|
||||||
|
var inArray = new BsonArray { name, arrayField };
|
||||||
|
var inDoc = new BsonDocument("$in", inArray);
|
||||||
|
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override string ContainsArrayUseSqlParameters(MethodCallExpressionModel model)
|
public override string ContainsArrayUseSqlParameters(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user