mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Update mongodb
This commit is contained in:
@@ -64,6 +64,20 @@ namespace MongoDbTest
|
||||
StudentName = x.Name,
|
||||
SchoolName = y.Name
|
||||
}).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")]
|
||||
public class Student : MongoDbBase
|
||||
|
@@ -215,11 +215,27 @@ namespace SqlSugar.MongoDb
|
||||
operations.Add(lookupDoc.ToJson(UtilMethods.GetJsonWriterSettings()));
|
||||
|
||||
// $unwind
|
||||
var unwindDoc = new BsonDocument("$unwind", new BsonDocument
|
||||
BsonValue unwindDoc = null;
|
||||
if (item.JoinType == JoinType.Left)
|
||||
{
|
||||
unwindDoc=new BsonDocument("$unwind", new BsonDocument
|
||||
{
|
||||
{ "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()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user