sdk/dotnet/src/Microsoft.Datasync.Client.SQLiteStore/OfflineSQLiteStore.cs
/// <summary>
/// Updates or inserts the item(s) provided in the table.
/// </summary>
/// <param name="tableName">The table to be used for the operation.</param>
/// <param name="items">The item(s) to be updated or inserted.</param>
/// <param name="ignoreMissingColumns">If <c>true</c>, extra properties on the item can be ignored.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the item has been updated or inserted into the table.</returns>
Updates or inserts the item(s) provided in the table.
Updates or inserts the item ( s ) provided in the table .
public override async Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool ignoreMissingColumns, CancellationToken cancellationToken = default)
        {
            Arguments.IsValidTableName(tableName, true, nameof(tableName));
            Arguments.IsNotNull(items, nameof(items));
            await EnsureInitializedAsync(cancellationToken).ConfigureAwait(false);
            TableDefinition table = GetTableOrThrow(tableName);
            var first = items.FirstOrDefault();
            if (first == null)
            {
                return;
            }
            var columns = new List<ColumnDefinition>();
            foreach (var prop in first.Properties())
            {
                if (!table.TryGetValue(prop.Name, out ColumnDefinition column) && !ignoreMissingColumns)
                {
                    throw new InvalidOperationException($"Column '{prop.Name}' is not defined on table '{tableName}'");
                }
                columns.Add(column);
            }
            if (columns.Count == 0)
            {
                return;
            }
            using (operationLock.AcquireLock())
            {
                ExecuteNonQueryInternal("BEGIN TRANSACTION");
                BatchInsert(tableName, items, columns.Where(c => c.IsIdColumn).Take(1).ToList());
                BatchUpdate(tableName, items, columns);
                ExecuteNonQueryInternal("COMMIT TRANSACTION");
            }
        }
public override async Task UpsertAsync ( string tableName , IEnumerable < JObject > items , bool ignoreMissingColumns , CancellationToken cancellationToken = default ) { Arguments . IsValidTableName ( tableName , true , nameof ( tableName ) ) ; Arguments . IsNotNull ( items , nameof ( items ) ) ; await EnsureInitializedAsync ( cancellationToken ) . ConfigureAwait ( false ) ; TableDefinition table = GetTableOrThrow ( tableName ) ; var first = items . FirstOrDefault ( ) ; if ( first == null ) { return ; } var columns = new List < ColumnDefinition > ( ) ; foreach ( var prop in first . Properties ( ) ) { if ( ! table . TryGetValue ( prop . Name , out ColumnDefinition column ) && ! ignoreMissingColumns ) { throw new InvalidOperationException ( $" Column ' { prop . Name } ' is not defined on table ' { tableName } ' " ) ; } columns . Add ( column ) ; } if ( columns . Count == 0 ) { return ; } using ( operationLock . AcquireLock ( ) ) { ExecuteNonQueryInternal ( " " ) ; BatchInsert ( tableName , items , columns . Where ( c => c . IsIdColumn ) . Take ( 1 ) . ToList ( ) ) ; BatchUpdate ( tableName , items , columns ) ; ExecuteNonQueryInternal ( " " ) ; } }
Updates or inserts the item(s) provided in the table.
Updates or inserts the item ( s ) provided in the table .
A task that completes when the item has been updated or inserted into the table.
A task that completes when the item has been updated or inserted into the table .
tableName
string
The table to be used for the operation.
The table to be used for the operation .
items
IEnumerable<JObject>
The item(s) to be updated or inserted.
The item ( s ) to be updated or inserted .
ignoreMissingColumns
bool
None
cancellationToken
CancellationToken
A  to observe.
A to observe .