Update mongodb

This commit is contained in:
sunkaixuan
2025-05-05 11:50:43 +08:00
parent 1cd5c98b87
commit be52e3e726
3 changed files with 15 additions and 38 deletions

View File

@@ -112,7 +112,8 @@ namespace MongoDb.Ado.data
throw new InvalidOperationException("No current document.");
var element = GetElementByOrdinal(ordinal);
return BsonTypeMapper.MapToDotNetValue(element.Value);
var result= BsonTypeMapper.MapToDotNetValue(element.Value);
return result;
}
private BsonElement GetElementByOrdinal(int ordinal)
{

View File

@@ -32,6 +32,8 @@ namespace MongoDbTest
.ExecuteCommand();
var list = db.Queryable<OrderInfo>().ToList();
//测试生成SQL性能
TestSqlBuilder(db);
}

View File

@@ -1,5 +1,7 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
namespace SqlSugar.MongoDb
@@ -46,42 +48,14 @@ namespace SqlSugar.MongoDb
}
public override string ToSqlString()
{
base.AppendFilter();
string oldOrderValue = this.OrderByValue;
string result = null;
sql = new StringBuilder();
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString);
if (IsCount) { return sql.ToString(); }
if (Skip != null && Take == null)
{
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString, Skip.ObjToInt(), long.MaxValue);
}
else if (Skip == null && Take != null)
{
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, 0, Take.ObjToInt());
}
else if (Skip != null && Take != null)
{
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, Skip.ObjToInt() > 0 ? Skip.ObjToInt() : 0, Take);
}
else
{
result = sql.ToString();
}
this.OrderByValue = oldOrderValue;
result = GetSqlQuerySql(result);
if (result.IndexOf("-- No table") > 0)
{
return "-- No table";
}
if (TranLock != null)
{
result = result + TranLock;
}
return result;
List<string> operations = new List<string>();
var sb = new StringBuilder();
sb.Append($"aggregate {this.GetTableNameString} ");
sb.Append("[");
sb.Append(string.Join(", ", operations));
sb.Append("]");
return sb.ToString();
}
#endregion