diff --git a/Storage/Storage.Test/ObjectControllerTests.cs b/Storage/Storage.Test/ObjectControllerTests.cs index ba7ee79..1e5b193 100644 --- a/Storage/Storage.Test/ObjectControllerTests.cs +++ b/Storage/Storage.Test/ObjectControllerTests.cs @@ -24,12 +24,12 @@ namespace LeanCloudTests { } [Test] - public async Task SaveWithQuery() { + public async Task SaveWithOptions() { AVObject account = AVObject.CreateWithoutData("Account", "5d65fa5330863b008065e476"); AVQuery query = new AVQuery("Account"); query.WhereGreaterThan("balance", 80); account["balance"] = 50; - await account.SaveAsync(query); + await account.SaveAsync(true, query); TestContext.Out.WriteLine($"balance: {account["balance"]}"); } diff --git a/Storage/Storage/Internal/Object/Controller/AVObjectController.cs b/Storage/Storage/Internal/Object/Controller/AVObjectController.cs index e0d4934..2eba634 100644 --- a/Storage/Storage/Internal/Object/Controller/AVObjectController.cs +++ b/Storage/Storage/Internal/Object/Controller/AVObjectController.cs @@ -35,6 +35,7 @@ namespace LeanCloud.Storage.Internal { public Task SaveAsync(IObjectState state, IDictionary operations, + bool fetchWhenSave, AVQuery query, string sessionToken, CancellationToken cancellationToken) { @@ -45,12 +46,16 @@ namespace LeanCloud.Storage.Internal { Method = state.ObjectId == null ? HttpMethod.Post : HttpMethod.Put, Content = objectJSON }; + Dictionary args = new Dictionary(); + if (fetchWhenSave) { + args.Add("fetchWhenSave", fetchWhenSave); + } // 查询条件 if (query != null && query.where != null) { - Dictionary where = new Dictionary { - { "where", PointerOrLocalIdEncoder.Instance.Encode(query.where) } - }; - string encode = AVClient.BuildQueryString(where); + args.Add("where", PointerOrLocalIdEncoder.Instance.Encode(query.where)); + } + if (args.Count > 0) { + string encode = AVClient.BuildQueryString(args); command.Path = $"{command.Path}?{encode}"; } return AVPlugins.Instance.CommandRunner.RunCommandAsync>(command, cancellationToken: cancellationToken).OnSuccess(t => { diff --git a/Storage/Storage/Public/AVObject.cs b/Storage/Storage/Public/AVObject.cs index a41a981..feb2fe9 100644 --- a/Storage/Storage/Public/AVObject.cs +++ b/Storage/Storage/Public/AVObject.cs @@ -557,7 +557,7 @@ string propertyName } } - public virtual Task SaveAsync(AVQuery query = null, CancellationToken cancellationToken = default) { + public virtual Task SaveAsync(bool fetchWhenSave = false, AVQuery query = null, CancellationToken cancellationToken = default) { IDictionary currentOperations = null; if (!IsDirty) { return Task.FromResult(0); @@ -577,6 +577,7 @@ string propertyName return deepSaveTask.OnSuccess(_ => { return ObjectController.SaveAsync(state, currentOperations, + FetchWhenSave || fetchWhenSave, query, sessionToken, cancellationToken); @@ -1501,6 +1502,10 @@ string propertyName } } + public bool FetchWhenSave { + get; set; + } + /// /// Indicates whether this AVObject has unsaved changes. ///