mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 12:09:29 +08:00
Update mongodb
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SqlSugar.MongoDb;
|
||||
using SqlSugar;
|
||||
using SqlSugar.MongoDb;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -22,6 +23,8 @@ namespace MongoDbTest
|
||||
db.Updateable(data1).ExecuteCommand();
|
||||
var data2 = db.Queryable<Student>().ToList();
|
||||
if (data2.First().Book.First().Price != 100) Cases.ThrowUnitError();
|
||||
var exp=Expressionable.Create<Student>().ToExpression();
|
||||
var data3 = db.Queryable<Student>().Where(exp).ToList();
|
||||
}
|
||||
|
||||
[SqlSugar.SugarTable("UnitStudentdfsds3zzz1")]
|
||||
|
@@ -17,10 +17,30 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
var result = new ExpressionVisitor(context).Visit(expr);
|
||||
if (result is BsonString bs)
|
||||
{
|
||||
result = new BsonDocument(UtilConstants.FieldName, bs);
|
||||
}
|
||||
result = TranslateStringToBson(bs);
|
||||
else if (result is BsonBoolean bb)
|
||||
result = TranslateBooleanToBson(bb);
|
||||
return (BsonDocument)result;
|
||||
}
|
||||
|
||||
private static BsonValue TranslateStringToBson(BsonString bs)
|
||||
{
|
||||
return new BsonDocument(UtilConstants.FieldName, bs);
|
||||
}
|
||||
|
||||
private static BsonValue TranslateBooleanToBson(BsonBoolean bb)
|
||||
{
|
||||
BsonValue result;
|
||||
if (bb == true)
|
||||
{
|
||||
result = new BsonDocument("$expr", new BsonDocument("$eq", new BsonArray { 1, 1 }));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new BsonDocument("$expr", new BsonDocument("$eq", new BsonArray { 1, 0 }));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user