mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Update mongodb
This commit is contained in:
@@ -11,12 +11,30 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
private BsonDocument GetComparisonOperation(BinaryExpression expr, BsonValue field, BsonValue value, bool leftIsMember, bool rightIsMember, string op)
|
private BsonDocument GetComparisonOperation(BinaryExpression expr, BsonValue field, BsonValue value, bool leftIsMember, bool rightIsMember, string op)
|
||||||
{
|
{
|
||||||
string leftValue = "";
|
var isLeftValue = IsLeftValue(leftIsMember, rightIsMember, op);
|
||||||
BsonValue rightValue = "";
|
var isRightValue = IsRightValue(leftIsMember, rightIsMember, op);
|
||||||
if (IsLeftValue(leftIsMember, rightIsMember, op) || IsRightValue(leftIsMember, rightIsMember, op))
|
var isKeyValue = isLeftValue || isRightValue;
|
||||||
|
if (isKeyValue)
|
||||||
|
return ComparisonKeyValue(expr, field, value, op, isLeftValue);
|
||||||
|
else
|
||||||
|
return ComparisonNotKeyValue(field, value, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BsonDocument ComparisonNotKeyValue(BsonValue field, BsonValue value, string op)
|
||||||
{
|
{
|
||||||
|
var leftKey = field.ToString();
|
||||||
|
return new BsonDocument
|
||||||
|
{
|
||||||
|
{ leftKey, new BsonDocument { { op, value } } }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private BsonDocument ComparisonKeyValue(BinaryExpression expr, BsonValue field, BsonValue value, string op, bool isLeftValue)
|
||||||
|
{
|
||||||
|
string leftValue = string.Empty;
|
||||||
|
BsonValue rightValue = null;
|
||||||
MemberExpression expression;
|
MemberExpression expression;
|
||||||
if (IsLeftValue(leftIsMember, rightIsMember, op))
|
if (isLeftValue)
|
||||||
{
|
{
|
||||||
leftValue = field.ToString();
|
leftValue = field.ToString();
|
||||||
rightValue = value;
|
rightValue = value;
|
||||||
@@ -59,14 +77,5 @@ namespace SqlSugar.MongoDb
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return new BsonDocument
|
|
||||||
{
|
|
||||||
{ field.ToString(), new BsonDocument { { op, value } } }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -472,7 +472,16 @@ namespace SqlSugar.MongoDb
|
|||||||
}
|
}
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
|
internal static BsonValue GetBsonValue(bool isMember, BsonValue field,bool isId)
|
||||||
|
{
|
||||||
|
if (!isMember && isId)
|
||||||
|
{
|
||||||
|
return ObjectId.Parse(field?.ToString());
|
||||||
|
}
|
||||||
|
if (isMember) return field.ToString();
|
||||||
|
else
|
||||||
|
return field;
|
||||||
|
}
|
||||||
internal static BsonValue GetBsonValue(bool isMember, BsonValue field)
|
internal static BsonValue GetBsonValue(bool isMember, BsonValue field)
|
||||||
{
|
{
|
||||||
if (isMember) return "$" + field;
|
if (isMember) return "$" + field;
|
||||||
|
Reference in New Issue
Block a user