mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update mongodb
This commit is contained in:
parent
ebb440a550
commit
b82b2de9ef
@ -26,6 +26,16 @@ namespace MongoDbTest
|
|||||||
|
|
||||||
//根据bool过滤
|
//根据bool过滤
|
||||||
FilterStudentsByBool(db);
|
FilterStudentsByBool(db);
|
||||||
|
|
||||||
|
//更多
|
||||||
|
InsertAndValidateStudent(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void InsertAndValidateStudent(SqlSugarClient db)
|
||||||
|
{
|
||||||
|
db.Insertable(new Student() { Name = "", Bool = true, CreateDateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
var list = db.Queryable<Student>().Where(it => string.IsNullOrEmpty(it.Name)).ToList();
|
||||||
|
if (!string.IsNullOrEmpty(list.First().Name)) Cases.ThrowUnitError();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FilterStudentsByBool(SqlSugar.SqlSugarClient db)
|
private static void FilterStudentsByBool(SqlSugar.SqlSugarClient db)
|
||||||
|
@ -570,16 +570,21 @@ namespace SqlSugar.MongoDb
|
|||||||
|
|
||||||
public override string IsNullOrEmpty(MethodCallExpressionModel model)
|
public override string IsNullOrEmpty(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
// 判断字符串是否为 null 或空字符串
|
// 获取字段名表达式
|
||||||
var item = model.Args[0].MemberValue ?? model.DataObject;
|
var item = model.Args[0].MemberValue ?? model.DataObject;
|
||||||
BsonValue memberName = new ExpressionVisitor(context).Visit(item as Expression);
|
var fieldExpr = new ExpressionVisitor(context).Visit(item as Expression);
|
||||||
// $or: [ { $eq: [ "$field", null ] }, { $eq: [ "$field", "" ] } ]
|
|
||||||
var orDoc = new BsonDocument("$or", new BsonArray
|
string fieldName = fieldExpr.ToString();
|
||||||
{
|
|
||||||
new BsonDocument("$eq", new BsonArray { $"${memberName}", BsonNull.Value }),
|
// 生成:{ "$match": { "$or": [ { "Name": null }, { "Name": "" } ] } }
|
||||||
new BsonDocument("$eq", new BsonArray { $"${memberName}", "" })
|
var or=new BsonDocument(
|
||||||
});
|
"$or", new BsonArray
|
||||||
return orDoc.ToJson(UtilMethods.GetJsonWriterSettings());
|
{
|
||||||
|
new BsonDocument(fieldName, BsonNull.Value),
|
||||||
|
new BsonDocument(fieldName, "")
|
||||||
|
});
|
||||||
|
|
||||||
|
return or.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Trim(MethodCallExpressionModel model)
|
public override string Trim(MethodCallExpressionModel model)
|
||||||
|
Loading…
Reference in New Issue
Block a user