mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-16 04:59:34 +08:00
Update mongodb
This commit is contained in:
parent
3c46dde2a4
commit
82ee75c9ca
@ -1,4 +1,5 @@
|
||||
using MongoDbTest.DBHelper;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@ -39,6 +40,10 @@ namespace MongoDbTest
|
||||
|
||||
var list4 = db.Queryable<OrderInfo>().OrderByDescending(it=>it.Price).ToList();
|
||||
|
||||
var list5 = db.Queryable<OrderInfo>().OrderByDescending(it => it.Price).ToList();
|
||||
|
||||
var list6 = db.Queryable<OrderInfo>().OrderByDescending(it => new { it.Id,Name=it.Name }).ToList();
|
||||
|
||||
//测试生成SQL性能
|
||||
TestSqlBuilder(db);
|
||||
}
|
||||
|
@ -88,20 +88,27 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
order = order.Substring("ORDER BY ".Length).Trim();
|
||||
|
||||
int lastSpace = order.LastIndexOf(' ');
|
||||
string jsonPart = order.Substring(0, lastSpace).Trim();
|
||||
string directionPart = order.Substring(lastSpace + 1).Trim().ToUpper();
|
||||
var sortDoc = new BsonDocument();
|
||||
foreach (var str in order.Split(","))
|
||||
{
|
||||
int lastSpace = str.LastIndexOf(' ');
|
||||
string jsonPart = str.Substring(0, lastSpace).Trim();
|
||||
string directionPart = str.Substring(lastSpace + 1).Trim().ToUpper();
|
||||
|
||||
var bson = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonPart);
|
||||
if (bson.Contains("fieldName"))
|
||||
var bson = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonPart);
|
||||
if (bson.Contains("fieldName"))
|
||||
{
|
||||
var field = bson["fieldName"].AsString;
|
||||
var direction = directionPart == "DESC" ? -1 : 1;
|
||||
sortDoc[field] = direction;
|
||||
}
|
||||
}
|
||||
if (sortDoc.ElementCount > 0)
|
||||
{
|
||||
var field = bson["fieldName"].AsString;
|
||||
var direction = directionPart == "ASC" ? 1 : -1;
|
||||
operations.Add($"{{ \"$sort\": {{ \"{field}\": {direction} }} }}");
|
||||
operations.Add($"{{ \"$sort\": {sortDoc.ToJson()} }}");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
sb.Append($"aggregate {this.GetTableNameString} ");
|
||||
sb.Append("[");
|
||||
sb.Append(string.Join(", ", operations));
|
||||
|
Loading…
Reference in New Issue
Block a user