mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Update mongodb
This commit is contained in:
@@ -60,6 +60,18 @@ namespace MongoDbTest
|
||||
if (list4.First().Day.Date != dt.Date.AddDays(1)) Cases.ThrowUnitError();
|
||||
if (list4.First().Year.Date != dt.Date.AddYears(1)) Cases.ThrowUnitError();
|
||||
if (list4.First().AddMonth.Date != dt.Date.AddMonths(1)) Cases.ThrowUnitError();
|
||||
|
||||
var list5 = db.Queryable<Student>().Select(it => new
|
||||
{
|
||||
Day =2
|
||||
}).ToList();
|
||||
if (list5.First().Day!=2) Cases.ThrowUnitError();
|
||||
|
||||
var list6 = db.Queryable<Student>().Select(it => new Student()
|
||||
{
|
||||
Age = 2
|
||||
}).ToList();
|
||||
if (list6.First().Age != 2) Cases.ThrowUnitError();
|
||||
}
|
||||
[SqlSugar.SugarTable("UnitStudent1231sds3z1")]
|
||||
public class Student : MongoDbBase
|
||||
|
@@ -52,7 +52,14 @@ namespace SqlSugar.MongoDb
|
||||
|
||||
// Build the projection document with the field name and its reference in MongoDB
|
||||
var json=new ExpressionVisitor(_context, _visitorContext).Visit(memberAssignment.Expression);
|
||||
projectionDocument[fieldName] = "$" + json.ToString();
|
||||
if (ExpressionTool.GetParameters(memberAssignment.Expression).Count == 0)
|
||||
{
|
||||
projectionDocument[fieldName] = json.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
projectionDocument[fieldName] = "$" + json.ToString();
|
||||
}
|
||||
}
|
||||
projectionDocument["_id"] = 0;
|
||||
return projectionDocument;
|
||||
|
@@ -41,25 +41,30 @@ namespace SqlSugar.MongoDb
|
||||
// 获取字段名
|
||||
var fieldName = member.Name;
|
||||
|
||||
var visExp = exp.Arguments[exp.Members.IndexOf(member)];
|
||||
// 使用 ExpressionVisitor 访问表达式
|
||||
var json = new ExpressionVisitor(_context, _visitorContext).Visit(exp.Arguments[exp.Members.IndexOf(member)]);
|
||||
var json = new ExpressionVisitor(_context, _visitorContext).Visit(visExp);
|
||||
|
||||
SetProjectionValue(json, fieldName, projectionDocument);
|
||||
SetProjectionValue(json, fieldName, projectionDocument, visExp);
|
||||
}
|
||||
projectionDocument["_id"] = 0;
|
||||
return projectionDocument;
|
||||
}
|
||||
|
||||
private static void SetProjectionValue(BsonValue json, string fieldName, BsonDocument projectionDocument)
|
||||
private static void SetProjectionValue(BsonValue json, string fieldName, BsonDocument projectionDocument, Expression visExp)
|
||||
{
|
||||
var jsonString = json.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||
if (jsonString.StartsWith("{") && jsonString.EndsWith("}"))
|
||||
{
|
||||
projectionDocument[fieldName] = json;
|
||||
}
|
||||
else if (ExpressionTool.GetParameters(visExp).Count == 0)
|
||||
{
|
||||
projectionDocument[fieldName] = jsonString ;
|
||||
}
|
||||
else
|
||||
{
|
||||
projectionDocument[fieldName] = "$"+jsonString.TrimStart('\"').TrimEnd('\"');
|
||||
projectionDocument[fieldName] = "$" + jsonString.TrimStart('\"').TrimEnd('\"');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user