mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update monodb
This commit is contained in:
parent
b0f582a97c
commit
746739826f
@ -1,4 +1,5 @@
|
|||||||
using MongoDB.Bson;
|
using Dm;
|
||||||
|
using MongoDB.Bson;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -31,21 +32,33 @@ namespace SqlSugar.MongoDb
|
|||||||
|
|
||||||
private BsonDocument ComparisonKeyValue(BinaryExpression expr, BsonValue field, BsonValue value, string op, bool isLeftValue)
|
private BsonDocument ComparisonKeyValue(BinaryExpression expr, BsonValue field, BsonValue value, string op, bool isLeftValue)
|
||||||
{
|
{
|
||||||
string leftValue = string.Empty;
|
string leftValue = isLeftValue ? field.ToString() : value.ToString();
|
||||||
BsonValue rightValue = null;
|
BsonValue rightValue = isLeftValue ? field : value;
|
||||||
MemberExpression expression;
|
var expression = isLeftValue ? expr.Left as MemberExpression : expr.Right as MemberExpression;
|
||||||
if (isLeftValue)
|
EntityColumnInfo CurrentColumnInfo = null;
|
||||||
{
|
leftValue = GetLeftValue(leftValue, expression, ref CurrentColumnInfo);
|
||||||
leftValue = field.ToString();
|
rightValue = GetRightValue(CurrentColumnInfo, rightValue);
|
||||||
rightValue = value;
|
if (IsEq(op))
|
||||||
expression = expr.Left as MemberExpression;
|
return GetEqResult(leftValue, rightValue);
|
||||||
}
|
else
|
||||||
else
|
return GetOtherResult(op, leftValue, rightValue);
|
||||||
{
|
}
|
||||||
leftValue = value.ToString();
|
|
||||||
rightValue = field;
|
private static BsonDocument GetOtherResult(string op, string leftValue, BsonValue rightValue)
|
||||||
expression = expr.Right as MemberExpression;
|
{
|
||||||
}
|
return new BsonDocument
|
||||||
|
{
|
||||||
|
{ leftValue, new BsonDocument { { op, rightValue } } }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BsonDocument GetEqResult(string leftValue, BsonValue rightValue)
|
||||||
|
{
|
||||||
|
return new BsonDocument { { leftValue, rightValue } };
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetLeftValue(string leftValue, MemberExpression expression, ref EntityColumnInfo CurrentColumnInfo)
|
||||||
|
{
|
||||||
if (expression != null)
|
if (expression != null)
|
||||||
{
|
{
|
||||||
if (expression.Expression is ParameterExpression parameter)
|
if (expression.Expression is ParameterExpression parameter)
|
||||||
@ -57,25 +70,21 @@ namespace SqlSugar.MongoDb
|
|||||||
if (columnInfo != null)
|
if (columnInfo != null)
|
||||||
{
|
{
|
||||||
leftValue = columnInfo.DbColumnName;
|
leftValue = columnInfo.DbColumnName;
|
||||||
if (columnInfo.IsPrimarykey)
|
CurrentColumnInfo = columnInfo;
|
||||||
{
|
|
||||||
rightValue = BsonValue.Create(ObjectId.Parse(value + ""));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (op == "$eq")
|
return leftValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BsonValue GetRightValue(EntityColumnInfo entityColumnInfo, BsonValue rightValue)
|
||||||
|
{
|
||||||
|
if (entityColumnInfo?.IsPrimarykey==true)
|
||||||
{
|
{
|
||||||
return new BsonDocument { { leftValue, rightValue } };
|
rightValue=ObjectId.Parse(rightValue?.ToString());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new BsonDocument
|
|
||||||
{
|
|
||||||
{ leftValue, new BsonDocument { { op, rightValue } } }
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
return rightValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
public partial class BinaryExpressionTranslator
|
public partial class BinaryExpressionTranslator
|
||||||
{
|
{
|
||||||
|
private static bool IsEq(string op)
|
||||||
|
{
|
||||||
|
return op == "$eq";
|
||||||
|
}
|
||||||
private void OutParameters(BinaryExpression expr, out BsonValue field, out BsonValue value, out bool leftIsMember, out bool rightIsMember, out string op)
|
private void OutParameters(BinaryExpression expr, out BsonValue field, out BsonValue value, out bool leftIsMember, out bool rightIsMember, out string op)
|
||||||
{
|
{
|
||||||
var leftVisitor = new ExpressionVisitor(_context, new ExpressionVisitorContext());
|
var leftVisitor = new ExpressionVisitor(_context, new ExpressionVisitorContext());
|
||||||
@ -29,8 +33,7 @@ namespace SqlSugar.MongoDb
|
|||||||
ExpressionType.LessThanOrEqual => "$lte",
|
ExpressionType.LessThanOrEqual => "$lte",
|
||||||
_ => null
|
_ => null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCalculationType(ExpressionType nodeType)
|
private static string GetCalculationType(ExpressionType nodeType)
|
||||||
{
|
{
|
||||||
return nodeType switch
|
return nodeType switch
|
||||||
|
Loading…
Reference in New Issue
Block a user