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 MongoDbTest.DBHelper;
|
||||||
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -39,6 +40,10 @@ namespace MongoDbTest
|
|||||||
|
|
||||||
var list4 = db.Queryable<OrderInfo>().OrderByDescending(it=>it.Price).ToList();
|
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性能
|
//测试生成SQL性能
|
||||||
TestSqlBuilder(db);
|
TestSqlBuilder(db);
|
||||||
}
|
}
|
||||||
|
@ -88,20 +88,27 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
order = order.Substring("ORDER BY ".Length).Trim();
|
order = order.Substring("ORDER BY ".Length).Trim();
|
||||||
|
|
||||||
int lastSpace = order.LastIndexOf(' ');
|
var sortDoc = new BsonDocument();
|
||||||
string jsonPart = order.Substring(0, lastSpace).Trim();
|
foreach (var str in order.Split(","))
|
||||||
string directionPart = order.Substring(lastSpace + 1).Trim().ToUpper();
|
{
|
||||||
|
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);
|
var bson = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonPart);
|
||||||
if (bson.Contains("fieldName"))
|
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;
|
operations.Add($"{{ \"$sort\": {sortDoc.ToJson()} }}");
|
||||||
var direction = directionPart == "ASC" ? 1 : -1;
|
|
||||||
operations.Add($"{{ \"$sort\": {{ \"{field}\": {direction} }} }}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
sb.Append($"aggregate {this.GetTableNameString} ");
|
sb.Append($"aggregate {this.GetTableNameString} ");
|
||||||
sb.Append("[");
|
sb.Append("[");
|
||||||
sb.Append(string.Join(", ", operations));
|
sb.Append(string.Join(", ", operations));
|
||||||
|
Loading…
Reference in New Issue
Block a user