mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Update Mongodb
This commit is contained in:
@@ -127,6 +127,17 @@ namespace MongoDbTest
|
|||||||
max=SqlFunc.AggregateMax(it.Id),
|
max=SqlFunc.AggregateMax(it.Id),
|
||||||
min=SqlFunc.AggregateMin(it.Id)
|
min=SqlFunc.AggregateMin(it.Id)
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
var list14 = db.Queryable<OrderInfo>()
|
||||||
|
.GroupBy(it => new { it.Name ,it.Price })
|
||||||
|
.Select(it => new
|
||||||
|
{
|
||||||
|
key = it.Name,
|
||||||
|
Prie=it.Price,
|
||||||
|
groupCount = SqlFunc.AggregateCount(it.Id),
|
||||||
|
max = SqlFunc.AggregateMax(it.Id),
|
||||||
|
min = SqlFunc.AggregateMin(it.Id)
|
||||||
|
}).ToList();
|
||||||
//测试生成SQL性能
|
//测试生成SQL性能
|
||||||
TestSqlBuilder(db);
|
TestSqlBuilder(db);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
using MongoDbTest;
|
using MongoDbTest;
|
||||||
//MongoDb还在开发中预计5月30号前可以使用
|
//MongoDb还在开发中预计6月30号前可以使用
|
||||||
OrmTest.Init();
|
OrmTest.Init();
|
||||||
AdoTest.Init();
|
AdoTest.Init();
|
||||||
ExpTest.Init();
|
ExpTest.Init();
|
||||||
|
@@ -115,8 +115,7 @@ namespace SqlSugar.MongoDb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
if (this.SelectValue is Expression expression)
|
if (this.SelectValue is Expression expression)
|
||||||
{
|
{
|
||||||
@@ -129,8 +128,7 @@ namespace SqlSugar.MongoDb
|
|||||||
operations.Add($"{{\"$project\": {json} }}");
|
operations.Add($"{{\"$project\": {json} }}");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region GroupBy
|
#region GroupBy
|
||||||
if (this.GroupByValue.HasValue())
|
if (this.GroupByValue.HasValue())
|
||||||
{
|
{
|
||||||
@@ -144,17 +142,20 @@ namespace SqlSugar.MongoDb
|
|||||||
var selectItem = match.Groups[1].Value;
|
var selectItem = match.Groups[1].Value;
|
||||||
selectItems.Add(selectItem);
|
selectItems.Add(selectItem);
|
||||||
}
|
}
|
||||||
var jsonPart = Regex.Split(this.GroupByValue, UtilConstants.ReplaceCommaKey)
|
var jsonPart = "["+Regex.Split(this.GroupByValue, UtilConstants.ReplaceCommaKey)
|
||||||
.First()
|
.First()
|
||||||
.TrimEnd('(')
|
.TrimEnd('(')
|
||||||
.Replace("GROUP BY ", "");
|
.Replace("GROUP BY ", "")+"]";
|
||||||
var fieldNames = new List<string>();
|
var fieldNames = new List<string>();
|
||||||
var bson = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonPart);
|
var bsonArray = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonArray>(jsonPart);
|
||||||
if (bson.Contains("fieldName"))
|
foreach (BsonDocument bson in bsonArray)
|
||||||
{
|
{
|
||||||
var field = bson["fieldName"].AsString;
|
if (bson.Contains("fieldName"))
|
||||||
operations[operations.Count - 1] = operations[operations.Count - 1].Replace($"\"${field}\"", $"\"$_id.{field}\"");
|
{
|
||||||
fieldNames.Add(field);
|
var field = bson["fieldName"].AsString;
|
||||||
|
operations[operations.Count - 1] = operations[operations.Count - 1].Replace($"\"${field}\"", $"\"$_id.{field}\"");
|
||||||
|
fieldNames.Add(field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 构造 _id 部分:支持多字段形式
|
// 构造 _id 部分:支持多字段形式
|
||||||
var groupId = new BsonDocument();
|
var groupId = new BsonDocument();
|
||||||
|
Reference in New Issue
Block a user