mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-24 04:53:45 +08:00
Update mongodb
This commit is contained in:
@@ -64,6 +64,20 @@ namespace MongoDbTest
|
|||||||
StudentName = x.Name,
|
StudentName = x.Name,
|
||||||
SchoolName = y.Name
|
SchoolName = y.Name
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
if (list.Count != 3) Cases.ThrowUnitError();
|
||||||
|
if (list.Any(s=>s.SchoolName== "TestSchool") ==false) Cases.ThrowUnitError();
|
||||||
|
if (list.Any(s => s.StudentName == "jack") == false) Cases.ThrowUnitError();
|
||||||
|
|
||||||
|
var list2 = db.Queryable<Student>()
|
||||||
|
.InnerJoin<School>((x, y) => x.SchoolId == y.Id)
|
||||||
|
.Select((x, y) => new
|
||||||
|
{
|
||||||
|
StudentName = x.Name,
|
||||||
|
SchoolName = y.Name
|
||||||
|
}).ToList();
|
||||||
|
if (list2.Count != 1) Cases.ThrowUnitError();
|
||||||
|
if (list2.Any(s => s.SchoolName == "TestSchool") == false) Cases.ThrowUnitError();
|
||||||
}
|
}
|
||||||
[SqlSugar.SugarTable("UnitStudent123131")]
|
[SqlSugar.SugarTable("UnitStudent123131")]
|
||||||
public class Student : MongoDbBase
|
public class Student : MongoDbBase
|
||||||
|
@@ -30,9 +30,9 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
return "ORDER BY NOW() ";
|
return "ORDER BY NOW() ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ToSqlString Items
|
#region ToSqlString Items
|
||||||
private void ProcessSelectConditions(List<string> operations)
|
private void ProcessSelectConditions(List<string> operations)
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ namespace SqlSugar.MongoDb
|
|||||||
var json = dos.ToJson(UtilMethods.GetJsonWriterSettings());
|
var json = dos.ToJson(UtilMethods.GetJsonWriterSettings());
|
||||||
operations.Add($"{{\"$project\": {json} }}");
|
operations.Add($"{{\"$project\": {json} }}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ProcessGroupByConditions(List<string> operations)
|
private void ProcessGroupByConditions(List<string> operations)
|
||||||
{
|
{
|
||||||
if (this.GroupByValue.HasValue())
|
if (this.GroupByValue.HasValue())
|
||||||
@@ -114,7 +114,7 @@ namespace SqlSugar.MongoDb
|
|||||||
}
|
}
|
||||||
operations.Insert(operations.Count - 1, groupDoc.ToJson(UtilMethods.GetJsonWriterSettings()));
|
operations.Insert(operations.Count - 1, groupDoc.ToJson(UtilMethods.GetJsonWriterSettings()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ProcessOrderByConditions(List<string> operations)
|
private void ProcessOrderByConditions(List<string> operations)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ namespace SqlSugar.MongoDb
|
|||||||
operations.Add($"{{ \"$match\": {trimmed} }}");
|
operations.Add($"{{ \"$match\": {trimmed} }}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ProcessJoinInfoConditions(List<string> operations)
|
private void ProcessJoinInfoConditions(List<string> operations)
|
||||||
{
|
{
|
||||||
foreach (var item in this.JoinQueryInfos)
|
foreach (var item in this.JoinQueryInfos)
|
||||||
@@ -215,11 +215,27 @@ namespace SqlSugar.MongoDb
|
|||||||
operations.Add(lookupDoc.ToJson(UtilMethods.GetJsonWriterSettings()));
|
operations.Add(lookupDoc.ToJson(UtilMethods.GetJsonWriterSettings()));
|
||||||
|
|
||||||
// $unwind
|
// $unwind
|
||||||
var unwindDoc = new BsonDocument("$unwind", new BsonDocument
|
BsonValue unwindDoc = null;
|
||||||
|
if (item.JoinType == JoinType.Left)
|
||||||
{
|
{
|
||||||
{ "path", $"${asName}" },
|
unwindDoc=new BsonDocument("$unwind", new BsonDocument
|
||||||
{ "preserveNullAndEmptyArrays", true }
|
{
|
||||||
});
|
{ "path", $"${asName}" },
|
||||||
|
{ "preserveNullAndEmptyArrays", true }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if(item.JoinType==JoinType.Inner)
|
||||||
|
{
|
||||||
|
// InnerJoin: 不保留空数组和null
|
||||||
|
unwindDoc = new BsonDocument("$unwind", new BsonDocument
|
||||||
|
{
|
||||||
|
{ "path", $"${asName}" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(" No Support "+item.JoinType);
|
||||||
|
}
|
||||||
operations.Add(unwindDoc.ToJson(UtilMethods.GetJsonWriterSettings()));
|
operations.Add(unwindDoc.ToJson(UtilMethods.GetJsonWriterSettings()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,8 +261,8 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
List<string> operations = new List<string>();
|
List<string> operations = new List<string>();
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
ProcessJoinInfoConditions(operations);
|
ProcessJoinInfoConditions(operations);
|
||||||
|
|
||||||
ProcessWhereConditions(operations);
|
ProcessWhereConditions(operations);
|
||||||
|
|
||||||
@@ -289,9 +305,9 @@ namespace SqlSugar.MongoDb
|
|||||||
{
|
{
|
||||||
this.SelectCacheKey = this.SelectCacheKey + string.Join("-", this.JoinQueryInfos.Select(it => it.TableName));
|
this.SelectCacheKey = this.SelectCacheKey + string.Join("-", this.JoinQueryInfos.Select(it => it.TableName));
|
||||||
}
|
}
|
||||||
if (IsDistinct)
|
if (IsDistinct)
|
||||||
{
|
{
|
||||||
result = "distinct "+result;
|
result = "distinct " + result;
|
||||||
}
|
}
|
||||||
if (this.SubToListParameters != null && this.SubToListParameters.Any())
|
if (this.SubToListParameters != null && this.SubToListParameters.Any())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user