public async Task RefreshAsync(T instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            MobileServiceSerializer serializer = this.MobileServiceClient.Serializer;
            object objId = serializer.GetId(instance, ignoreCase: false, allowDefault: true);

            if (objId == null)
            {
                return; // refresh is not supposed to throw if your object does not have an id for some reason
            }

            string id = EnsureIdIsString(objId);

            // Get the latest version of this element
            JObject refreshed = await base.LookupAsync(id);

            if (refreshed == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Item not found in local store."));
            }

            // Deserialize that value back into the current instance
            serializer.Deserialize <T>(refreshed, instance);
        }
        // we don't support int id tables for offline. therefore id must be of type string
        private static string EnsureIdIsString(JObject instance)
        {
            Arguments.IsNotNull(instance, nameof(instance));

            object id = MobileServiceSerializer.GetId(instance, ignoreCase: false, allowDefault: false);

            return(EnsureIdIsString(id));
        }
        // we don't support int id tables for offline. therefore id must be of type string
        private static string EnsureIdIsString(JObject instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            object id = MobileServiceSerializer.GetId(instance, ignoreCase: false, allowDefault: false);

            return(EnsureIdIsString(id));
        }
        public async Task <JObject> InsertAsync(JObject instance)
        {
            object id = MobileServiceSerializer.GetId(instance, ignoreCase: false, allowDefault: true);

            if (id == null)
            {
                id       = Guid.NewGuid().ToString();
                instance = (JObject)instance.DeepClone();
                instance[MobileServiceSystemColumns.Id] = (string)id;
            }
            else
            {
                EnsureIdIsString(id);
            }

            await this.syncContext.InsertAsync(this.TableName, this.Kind, (string)id, instance);

            return(instance);
        }