diff --git a/Storage/Storage.Test/ObjectTest.cs b/Storage/Storage.Test/ObjectTest.cs index 6154554..038da98 100644 --- a/Storage/Storage.Test/ObjectTest.cs +++ b/Storage/Storage.Test/ObjectTest.cs @@ -293,5 +293,15 @@ namespace LeanCloud.Test { }; await p.Save(); } + + [Test] + public async Task SaveWithQuery() { + AVObject p = new AVObject("P"); + AVObject c1 = AVObject.CreateWithoutData("C1", "5dea05578a84ab00680b7ae5"); + AVObject c2 = new AVObject("C2"); + p["c"] = c1; + c1["c"] = c2; + await p.Save(); + } } -} \ No newline at end of file +} diff --git a/Storage/Storage/Public/AVObject.cs b/Storage/Storage/Public/AVObject.cs index 72739d0..d7ae6f6 100644 --- a/Storage/Storage/Public/AVObject.cs +++ b/Storage/Storage/Public/AVObject.cs @@ -1567,15 +1567,10 @@ string propertyName static Stack BatchObjects(IEnumerable avObjects) { Stack batches = new Stack(); + batches.Push(new Batch(avObjects)); - IEnumerable deps = avObjects; - do { - // 只添加本层依赖的 LCObject - IEnumerable depAVObjs = deps.OfType(); - if (depAVObjs.Any()) { - batches.Push(new Batch(depAVObjs)); - } - + IEnumerable deps = from avObj in avObjects select avObj.estimatedData.Values; + do { HashSet childSets = new HashSet(); foreach (object dep in deps) { IEnumerable children = null; @@ -1585,6 +1580,7 @@ string propertyName children = (dep as IDictionary).Values; } else if (dep is AVObject && (dep as AVObject).ObjectId == null) { // 如果依赖是 AVObject 类型并且还没有保存过,则应该遍历其依赖 + // TODO 这里应该是从 Operation 中查找新增的对象 children = (dep as AVObject).estimatedData.Values; } if (children != null) { @@ -1593,6 +1589,10 @@ string propertyName } } } + IEnumerable depAVObjs = deps.OfType().Where(o => o.ObjectId == null); + if (depAVObjs.Any()) { + batches.Push(new Batch(depAVObjs)); + } deps = childSets; } while (deps != null && deps.Any());