public int Update (UpdateOptions updateOptions) { throw new NotImplementedException (); }
public void UpdateMany <TDoc>(string collectionName, TDoc doc, Expression <Func <TDoc, bool> > filter, UpdateOptions options = null) { var colleciton = GetMongoCollection <TDoc>(collectionName); List <UpdateDefinition <TDoc> > updateList = BuildUpdateDefinition <TDoc>(doc, null); colleciton.UpdateMany(filter, Builders <TDoc> .Update.Combine(updateList), options); }
/// <summary> /// Initializes a new instance of the <see cref="AccessUpdateMany" /> class. /// </summary> /// <param name="dataSource">The data source.</param> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values.</param> /// <param name="options">The options.</param> /// <exception cref="System.NotSupportedException">Cannot use Key attributes with this operation.</exception> public AccessUpdateMany(AccessDataSourceBase dataSource, AccessObjectName tableName, object newValues, UpdateOptions options) : base(dataSource) { if (options.HasFlag(UpdateOptions.UseKeyAttribute)) { throw new NotSupportedException("Cannot use Key attributes with this operation."); } m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName); m_NewValues = newValues; m_Options = options; }
public static T Upsert2 <T>(this ILiteRepository repository, Expression <Func <T, bool> > filter, T data, UpdateOptions options = null) { // 查找是否存在 T exist = repository.Query <T>().Where(filter).FirstOrDefault(); // 如果不存在,新建 if (exist == null) { repository.Insert(data); return(data); } // 更新数据 Type tt = data.GetType(); var properties = tt.GetProperties().Where(p => options == null || options.Validate(p.Name)); foreach (var prop in properties) { object value = prop.GetValue(data); // 给exist赋值 prop.SetValue(exist, value); } // 更新到数据库 repository.Upsert(exist); return(exist); }
public void Update <TDoc>(string collectionName, TDoc doc, Expression <Func <TDoc, bool> > filter, UpdateDefinition <TDoc> updateFields, UpdateOptions options = null) { var colleciton = GetMongoCollection <TDoc>(collectionName); colleciton.UpdateOne(filter, updateFields, options); }
public int UpdateRows(DataRow[] dataRows, UpdateOptions updateOptions) { throw new NotImplementedException(); }
[DisableRequestSizeLimit] // note we added this to disable the 30M request limit https://github.com/aspnet/Announcements/issues/267 public async Task <IActionResult> Upload() { try { Log(string.Empty); if (!IsMultipartContentType(Request.ContentType)) { LogWarning("Content is not multipart."); return(BadRequest()); } var boundary = GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType)); if (boundary == null) { LogWarning("Boundary was not found."); return(BadRequest()); } // note we expect the json document to arrive before the file document UpdateRequest updateRequest = null; MultipartSection dataSection = null; var reader = new MultipartReader(boundary, HttpContext.Request.Body); do { var section = await reader.ReadNextSectionAsync().ConfigureAwait(false); if (section == null) { break; } if (string.IsNullOrWhiteSpace(section.ContentType)) { continue; } if (updateRequest == null) { if (!MediaTypeHeaderValue.TryParse(new StringSegment(section.ContentType), out var mediaType) || string.IsNullOrWhiteSpace(mediaType.MediaType.Value)) { continue; } if (mediaType.MediaType.Value.Contains("/json")) { try { updateRequest = await JsonSerializer.DeserializeAsync <UpdateRequest>(section.Body).ConfigureAwait(false); Log("Request id : " + updateRequest.Id + " name: " + updateRequest.Name + " parentId: " + updateRequest.ParentId + " attributes: " + updateRequest.Attributes); } catch (Exception e) { LogWarning("Invalid json document: " + e.Message); return(BadRequest()); } } continue; } else if (dataSection == null) { if (!section.ContentType.Equals("application/octet-stream")) { continue; } dataSection = section; break; // don't continue, we don't want to read the rest of stream } }while (true); if (updateRequest == null) { LogWarning("Request was not found."); return(BadRequest()); } var updateOptions = UpdateOptions.FromUpdateRequest(updateRequest); if (updateRequest.Id == Guid.Empty) { // creation var parent = await FileSystem.GetItemAsync(updateRequest.ParentId).ConfigureAwait(false); if (parent == null) { LogWarning("Parent " + updateRequest.ParentId + " was not found."); return(BadRequest()); } if (!parent.IsFolder()) { LogWarning("Parent " + parent.Id + " is not a folder."); return(BadRequest()); } var createOptions = new CreateOptions(); if (dataSection != null) { createOptions.InputStream = dataSection.Body; } createOptions.Attributes = updateRequest.Attributes ?? FileAttributes.Normal; var created = await((IFolderInfo)parent).CreateAsync(updateRequest.Name, createOptions).ConfigureAwait(false); if (updateOptions != null) { await created.UpdateAsync(updateOptions).ConfigureAwait(false); } return(Ok(created)); } var item = await FileSystem.GetItemAsync(updateRequest.Id).ConfigureAwait(false); if (item == null) { LogWarning("Item " + updateRequest.Id + " was not found."); return(BadRequest()); } if (item.IsFolder()) { if (dataSection != null) { LogWarning("Item " + updateRequest.Id + " is a folder so it's content cannot be set."); return(BadRequest()); } if (updateOptions != null) { await item.UpdateAsync(updateOptions).ConfigureAwait(false); } return(Ok(item)); } var file = (IFileInfo)item; if (dataSection != null) { await file.WriteAsync(dataSection.Body).ConfigureAwait(false); } if (updateOptions != null) { await item.UpdateAsync(updateOptions).ConfigureAwait(false); } return(Ok(item)); } catch (UnauthorizedAccessException) { return(Unauthorized()); } }
IUpdateManyCommandBuilder IClass1DataSource.UpdateSet(string tableName, object newValues, UpdateOptions options) { return(UpdateSet(tableName, newValues, options)); }
public override void Update(FilterDefinition <TEntity> filter, UpdateDefinition <TEntity> update, UpdateOptions options) { throw new ReadOnlyException(); }
IMultipleRowDbCommandBuilder IClass1DataSource.UpdateByKeyList <TArgument, TKey>(string tableName, TArgument newValues, IEnumerable <TKey> keys, UpdateOptions options) { return(UpdateByKeyList(tableName, newValues, keys, options)); }
IUpdateManyCommandBuilder IClass1DataSource.UpdateSet(string tableName, string updateExpression, object updateArgumentValue, UpdateOptions options) { return(UpdateSet(tableName, updateExpression, updateArgumentValue, options)); }
ISingleRowDbCommandBuilder IClass1DataSource.UpdateByKey <TArgument>(string tableName, TArgument newValues, string key, UpdateOptions options) { return(UpdateByKey(tableName, newValues, key, options)); }
IObjectDbCommandBuilder <TArgument> IClass1DataSource.Update <TArgument>(TArgument argumentValue, UpdateOptions options) { return(Update(argumentValue, options)); }
IObjectDbCommandBuilder <TArgument> IClass1DataSource.Update <TArgument>(string tableName, TArgument argumentValue, UpdateOptions options) { return(Update(tableName, argumentValue, options)); }
public int UpdateRows (DataRow[] dataRows, UpdateOptions updateOptions) { throw new NotImplementedException (); }
public override Task UpdateManyAsync(FilterDefinition <TEntity> filter, UpdateDefinition <TEntity> update, UpdateOptions options) { throw new ReadOnlyException(); }
public async Task <UpdateResult> excuteMongoLinqUpdateColumns <T>(FilterDefinition <T> filters, UpdateDefinition <T> documents, UpdateOptions option, string connectionString, string databaseName, string collectionName, bool isCache, string key, DateTime cacheTime, string type = "updatelinqcolumns" ) where T : class { try { key = "updatelinqcolumns"; var client = getMongoClient(connectionString); var db = client.GetDatabase(databaseName); var collection = db.GetCollection <T>(collectionName); try { var rs = await collection.UpdateOneAsync(filters, documents, option); // var rs = await collection.UpdateManyAsync(filter: filters, update: documents, options: option); return(rs); } catch (Exception ex) { // CacheBase.cacheManagerSetForLinqUpdate<T>(key, filters, documents, option, cacheTime, connectionString, databaseName, collectionName, type); } } catch (Exception ex) { } return(null); }
/// <summary> /// Updates an object in the specified table. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="argumentValue">The argument value.</param> /// <param name="options">The update options.</param> /// <returns>SqlServerInsert.</returns> public ObjectDbCommandBuilder <OleDbCommand, OleDbParameter, TArgument> Update <TArgument>(SqlServerObjectName tableName, TArgument argumentValue, UpdateOptions options = UpdateOptions.None) where TArgument : class { return(new OleDbSqlServerUpdateObject <TArgument>(this, tableName, argumentValue, options)); }
public int UpdateRows(DataRow[] dataRows, UpdateOptions updateOptions, DbTransaction transaction) { throw new NotImplementedException(); }
/// <summary> /// Updates an object in the specified table. /// </summary> /// <typeparam name="TArgument"></typeparam> /// <param name="argumentValue">The argument value.</param> /// <param name="options">The update options.</param> /// <returns></returns> public ObjectDbCommandBuilder <OleDbCommand, OleDbParameter, TArgument> Update <TArgument>(TArgument argumentValue, UpdateOptions options = UpdateOptions.None) where TArgument : class { return(Update(DatabaseMetadata.GetTableOrViewFromClass <TArgument>().Name, argumentValue, options)); }
/// <summary> /// Bulk update a collection of objects into the database. /// </summary> /// <param name="context">The EntityFramework DbContext object.</param> /// <param name="entities">The collection of objects to be updated.</param> /// <param name="options"></param> /// <typeparam name="TEntity">The type of the objects collection. TEntity must be a class.</typeparam> /// <returns>The number of affected rows.</returns> public static int BulkUpdate <TEntity>(this DbContext context, IEnumerable <TEntity> entities, UpdateOptions options = UpdateOptions.Default) where TEntity : class { return(context.GetContextWrapper <TEntity>().CommitTransaction(entities, Operation.Update, options.ToSharedOptions())); }
/// <summary> /// Delete a record by its primary key. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values to use.</param> /// <param name="key">The key.</param> /// <param name="options">The options.</param> /// <returns>MultipleRowDbCommandBuilder<OleDbCommand, OleDbParameter>.</returns> public SingleRowDbCommandBuilder <OleDbCommand, OleDbParameter> UpdateByKey <TArgument, TKey>(SqlServerObjectName tableName, TArgument newValues, TKey key, UpdateOptions options = UpdateOptions.None) where TKey : struct { return(UpdateByKeyList(tableName, newValues, new List <TKey> { key }, options)); }
public void Update <TDoc>(TDoc doc, Expression <Func <TDoc, bool> > filter, UpdateDefinition <TDoc> updateFields, UpdateOptions options = null) { string collectionName = typeof(TDoc).Name; Update <TDoc>(collectionName, doc, filter, updateFields, options); }
/// <summary> /// Delete a record by its primary key. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values to use.</param> /// <param name="key">The key.</param> /// <param name="options">The options.</param> /// <returns>MultipleRowDbCommandBuilder<OleDbCommand, OleDbParameter>.</returns> public SingleRowDbCommandBuilder <OleDbCommand, OleDbParameter> UpdateByKey <TArgument>(SqlServerObjectName tableName, TArgument newValues, string key, UpdateOptions options = UpdateOptions.None) { return(UpdateByKeyList(tableName, newValues, new List <string> { key }, options)); }
public void UpdateMany <TDoc>(TDoc doc, Expression <Func <TDoc, bool> > filter, UpdateOptions options = null) { string collectionName = typeof(TDoc).Name; UpdateMany <TDoc>(collectionName, doc, filter, options); }
public MultipleRowDbCommandBuilder <OleDbCommand, OleDbParameter> UpdateByKeyList <TArgument, TKey>(SqlServerObjectName tableName, TArgument newValues, IEnumerable <TKey> keys, UpdateOptions options = UpdateOptions.None) { var primaryKeys = DatabaseMetadata.GetTableOrView(tableName).Columns.Where(c => c.IsPrimaryKey).ToList(); if (primaryKeys.Count != 1) { throw new MappingException($"UpdateByKey operation isn't allowed on {tableName} because it doesn't have a single primary key."); } var keyList = keys.AsList(); var columnMetadata = primaryKeys.Single(); string where; if (keys.Count() > 1) { where = columnMetadata.SqlName + " IN (" + string.Join(", ", keyList.Select((s, i) => "?")) + ")"; } else { where = columnMetadata.SqlName + " = ?"; } var parameters = new List <OleDbParameter>(); for (var i = 0; i < keyList.Count; i++) { var param = new OleDbParameter("@Param" + i, keyList[i]); if (columnMetadata.DbType.HasValue) { param.OleDbType = columnMetadata.DbType.Value; } parameters.Add(param); } return(new OleDbSqlServerUpdateMany(this, tableName, newValues, where, parameters, parameters.Count, options)); }
/// <summary> /// Initializes a new instance of the <see cref="AccessUpdateMany" /> class. /// </summary> /// <param name="dataSource">The data source.</param> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values.</param> /// <param name="whereClause">The where clause.</param> /// <param name="parameters">The parameters.</param> /// <param name="expectedRowCount">The expected row count.</param> /// <param name="options">The options.</param> public AccessUpdateMany(AccessDataSourceBase dataSource, AccessObjectName tableName, object newValues, string whereClause, IEnumerable <OleDbParameter> parameters, int?expectedRowCount, UpdateOptions options) : base(dataSource) { if (options.HasFlag(UpdateOptions.UseKeyAttribute)) { throw new NotSupportedException("Cannot use Key attributes with this operation."); } m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName); m_NewValues = newValues; m_WhereClause = whereClause; m_ExpectedRowCount = expectedRowCount; m_Options = options; m_Parameters = parameters; }
/// <summary> /// Initializes a new instance of the <see cref="SQLiteUpdateObject{TArgument}"/> class. /// </summary> /// <param name="dataSource">The data source.</param> /// <param name="tableName">Name of the table.</param> /// <param name="argumentValue">The argument value.</param> /// <param name="options">The options.</param> public SQLiteUpdateObject(SQLiteDataSourceBase dataSource, SQLiteObjectName tableName, TArgument argumentValue, UpdateOptions options) : base(dataSource, tableName, argumentValue) { m_Options = options; }
/// <summary> /// Initializes a new instance of the <see cref="AccessUpdateMany" /> class. /// </summary> /// <param name="dataSource">The data source.</param> /// <param name="tableName">Name of the table.</param> /// <param name="updateExpression">The update expression.</param> /// <param name="updateArgumentValue">The update argument value.</param> /// <param name="options">The options.</param> /// <exception cref="System.NotSupportedException">Cannot use Key attributes with this operation.</exception> public AccessUpdateMany(AccessDataSourceBase dataSource, AccessObjectName tableName, string updateExpression, object updateArgumentValue, UpdateOptions options) : base(dataSource) { if (options.HasFlag(UpdateOptions.UseKeyAttribute)) { throw new NotSupportedException("Cannot use Key attributes with this operation."); } m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName); m_UpdateExpression = updateExpression; m_Options = options; m_UpdateArgumentValue = updateArgumentValue; }
public int Update(UpdateOptions updateOptions) { throw new NotImplementedException(); }
public int Update (UpdateOptions updateOptions, DbTransaction transaction) { throw new NotImplementedException (); }
public int Update(UpdateOptions updateOptions, DbTransaction transaction) { throw new NotImplementedException(); }
public int UpdateRows (DataRow[] dataRows, UpdateOptions updateOptions, DbTransaction transaction) { throw new NotImplementedException (); }
public async Task <ReplaceOneResult> excuteMongoLinqUpdate <T>(FilterDefinition <T> filters, T documents, UpdateOptions option, string connectionString, string databaseName, string collectionName, bool isCache, string key, DateTime cacheTime, string type = "updatelinq" ) where T : class { try { key = "updatelinq"; //CacheBase.cacheModifyAllKeyLinqUpdate(key); var client = getMongoClient(connectionString); var db = client.GetDatabase(databaseName); var collection = db.GetCollection <T>(collectionName); try { var rs = await collection.ReplaceOneAsync(filters, documents, option); // var rs = await collection.UpdateManyAsync(filter: filters, update: documents, options: option); if (rs != null && (rs.MatchedCount > 0 || rs.ModifiedCount > 0 || rs.UpsertedId != null)) { ; } else { // CacheBase.cacheManagerSetForLinqUpdate<T>(key, filters, documents, option, cacheTime, connectionString, databaseName, collectionName, type); } return(rs); } catch (Exception ex) { // CacheBase.cacheManagerSetForLinqUpdate<T>(key, filters, documents, option, cacheTime, connectionString, databaseName, collectionName, type); } } catch (Exception ex) { } return(null); }