mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Update mongodb
This commit is contained in:
@@ -198,6 +198,13 @@ namespace MongoDbTest
|
|||||||
|
|
||||||
var list25 = db.Queryable<Student>().Where(it => it.Name == it.Name && it.Name=="a").ToList();
|
var list25 = db.Queryable<Student>().Where(it => it.Name == it.Name && it.Name=="a").ToList();
|
||||||
if (list25.Count!=1||list25.First().Name != "a") Cases.ThrowUnitError();
|
if (list25.Count!=1||list25.First().Name != "a") Cases.ThrowUnitError();
|
||||||
|
|
||||||
|
var list26 = db.Queryable<Student>().Select(it => new
|
||||||
|
{
|
||||||
|
Age1 = it.Age > 0? it.Age: 1,
|
||||||
|
Age2 =SqlFunc.IIF( it.Age > 0 , it.Age ,1),
|
||||||
|
}).ToList();
|
||||||
|
if (list26.First().Age1 != list26.First().Age2) Cases.ThrowUnitError();
|
||||||
}
|
}
|
||||||
[SqlSugar.SugarTable("UnitStudent1231sds3z1")]
|
[SqlSugar.SugarTable("UnitStudent1231sds3z1")]
|
||||||
public class Student : MongoDbBase
|
public class Student : MongoDbBase
|
||||||
|
@@ -60,6 +60,10 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
projectionDocument[fieldName] = json;
|
projectionDocument[fieldName] = json;
|
||||||
}
|
}
|
||||||
|
else if (memberAssignment.Expression is MethodCallExpression callExpression&&callExpression.Method.Name==nameof(SqlFunc.IIF))
|
||||||
|
{
|
||||||
|
projectionDocument[fieldName] = json;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
projectionDocument[fieldName] = "$" + json.ToString();
|
projectionDocument[fieldName] = "$" + json.ToString();
|
||||||
|
@@ -45,7 +45,7 @@ namespace SqlSugar.MongoDb
|
|||||||
var funcString = context.ToString(model);
|
var funcString = context.ToString(model);
|
||||||
result = BsonDocument.Parse(funcString);
|
result = BsonDocument.Parse(funcString);
|
||||||
}
|
}
|
||||||
else if (name.StartsWith("To"))
|
else if (name.StartsWith("To")||name==nameof(SqlFunc.IIF))
|
||||||
{
|
{
|
||||||
var value = context.GetType().GetMethod(name).Invoke(context, new object[] { model });
|
var value = context.GetType().GetMethod(name).Invoke(context, new object[] { model });
|
||||||
result = BsonDocument.Parse(value?.ToString());
|
result = BsonDocument.Parse(value?.ToString());
|
||||||
|
@@ -662,6 +662,20 @@ namespace SqlSugar.MongoDb
|
|||||||
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
|
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string IIF(MethodCallExpressionModel model)
|
||||||
|
{
|
||||||
|
|
||||||
|
var test = model.Args[0].MemberValue as Expression;
|
||||||
|
var ifTrue = model.Args[1].MemberValue as Expression;
|
||||||
|
var ifFalse = model.Args[2].MemberValue as Expression;
|
||||||
|
|
||||||
|
// 构造 ConditionalExpression
|
||||||
|
var conditionalExpr = Expression.Condition(test, ifTrue, ifFalse);
|
||||||
|
|
||||||
|
BsonValue testValue = new ConditionalExpressionTractor(context, null).Extract(conditionalExpr);
|
||||||
|
return testValue.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||||
|
}
|
||||||
|
|
||||||
#region Helper
|
#region Helper
|
||||||
private static BsonValue GetMemberName(BsonValue memberName)
|
private static BsonValue GetMemberName(BsonValue memberName)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user