private async Task<Tuple<IEnumerable<IDictionary<string, object>>, int>> RetrieveEntriesWithCountAsync( string commandText, bool scalarResult) { var command = new CommandWriter(_schema).CreateGetCommand(commandText, scalarResult); var request = _requestBuilder.CreateRequest(command); var result = await _requestRunner.FindEntriesWithCountAsync(request, scalarResult); return Tuple.Create(result.Item1, result.Item2); }
private async Task<IDictionary<string, object>> UpdateEntryPropertiesAndAssociationsAsync( string collection, IDictionary<string, object> entryKey, IDictionary<string, object> entryData, EntryMembers entryMembers, bool resultRequired) { bool hasPropertiesToUpdate = entryMembers.Properties.Count > 0; bool merge = !hasPropertiesToUpdate || CheckMergeConditions(collection, entryKey, entryData); var commandText = await GetFluentClient() .For(_schema.FindBaseTable(collection).ActualName) .Key(entryKey) .GetCommandTextAsync(); var commandWriter = new CommandWriter(_schema); var table = _schema.FindConcreteTable(collection); var entryContent = commandWriter.CreateEntry(table.EntityType.Name, entryMembers.Properties); var unlinkAssociationNames = new List<string>(); foreach (var associatedData in entryMembers.AssociationsByValue) { var association = table.FindAssociation(associatedData.Key); if (associatedData.Value != null) { commandWriter.AddLink(entryContent, collection, associatedData); } else { unlinkAssociationNames.Add(association.ActualName); } } var command = commandWriter.CreateUpdateCommand(commandText, entryData, entryContent, merge); var request = _requestBuilder.CreateRequest(command, resultRequired); var result = await _requestRunner.UpdateEntryAsync(request); foreach (var associatedData in entryMembers.AssociationsByContentId) { var linkCommand = commandWriter.CreateLinkCommand(collection, associatedData.Key, command.ContentId, associatedData.Value); request = _requestBuilder.CreateRequest(linkCommand); await _requestRunner.UpdateEntryAsync(request); } foreach (var associationName in unlinkAssociationNames) { await UnlinkEntryAsync(collection, entryKey, associationName); } return result; }