in src/WebJobs.Extensions.MobileApps/Bindings/MobileTableAsyncCollector.cs [21:50]
public async Task AddAsync(T item, CancellationToken cancellationToken = default(CancellationToken))
{
if (typeof(T) == typeof(JObject) || typeof(T) == typeof(object))
{
if (string.IsNullOrEmpty(_context.ResolvedAttribute.TableName))
{
throw new InvalidOperationException("The table name must be specified.");
}
// If the item is an object, that is inferred to mean it is an anonymous type and we convert it directly
// to a JObject. Items of type object are not directly usable with the Mobile Service client as there is
// no 'Id' property on Object. This adds some useful functionality from scripting where you don't need to
// define models or add references to JSON.NET in order to add data to table.
JObject convertedItem = JObject.FromObject(item);
IMobileServiceTable table = _context.Client.GetTable(_context.ResolvedAttribute.TableName);
await table.InsertAsync(convertedItem);
}
else
{
// If TableName is specified, add it to the internal table cache. Now items of this type
// will operate on the specified TableName.
if (!string.IsNullOrEmpty(_context.ResolvedAttribute.TableName))
{
_context.Client.AddToTableNameCache(item.GetType(), _context.ResolvedAttribute.TableName);
}
IMobileServiceTable<T> table = _context.Client.GetTable<T>();
await table.InsertAsync(item);
}
}