/// <summary> /// IMPORTANT: This operation supported only by Microsoft SQL Server. /// Adds new update by source operation to merge and returns new merge command with added operation. /// This operation updates record in target table for each record that was matched only in target /// using user-defined values for target columns, if it passed filtering by operation predicate and /// wasn't processed by previous operations. /// </summary> /// <typeparam name="TTarget">Target record type.</typeparam> /// <typeparam name="TSource">Source record type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <param name="searchCondition">Operation execution condition over target record.</param> /// <param name="setter">Update record expression using target record. Expression should be a call to /// target record constructor with field/properties initializers to be recognized by API.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TSource> UpdateWhenNotMatchedBySourceAnd <TTarget, TSource>( this IMergeableSource <TTarget, TSource> merge, Expression <Func <TTarget, bool> > searchCondition, Expression <Func <TTarget, TTarget> > setter) where TTarget : class where TSource : class { if (merge == null) { throw new ArgumentNullException("merge"); } if (searchCondition == null) { throw new ArgumentNullException("searchCondition"); } if (setter == null) { throw new ArgumentNullException("setter"); } return(((MergeDefinition <TTarget, TSource>)merge).AddOperation( MergeDefinition <TTarget, TSource> .Operation.UpdateBySource(searchCondition, setter))); }
/// <summary> /// IMPORTANT: This operation supported only by Oracle Database. /// Adds new update with delete operation to merge and returns new merge command with added operation. /// This operation updates record in target table using user-defined values for target columns /// for each record that was matched in source and target and passes filtering with specified predicate, /// if it wasn't processed by previous operations. /// After that it removes updated records if they matched by delete predicate. /// </summary> /// <typeparam name="TTarget">Target record type.</typeparam> /// <typeparam name="TSource">Source record type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <param name="searchCondition">Update execution condition over target and source records.</param> /// <param name="setter">Update record expression using target and source records. /// Expression should be a call to target record constructor with field/properties initializers to be recognized by API.</param> /// <param name="deleteCondition">Delete execution condition over updated target and source records.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TSource> UpdateWhenMatchedAndThenDelete <TTarget, TSource>( this IMergeableSource <TTarget, TSource> merge, Expression <Func <TTarget, TSource, bool> > searchCondition, Expression <Func <TTarget, TSource, TTarget> > setter, Expression <Func <TTarget, TSource, bool> > deleteCondition) where TTarget : class where TSource : class { if (merge == null) { throw new ArgumentNullException(nameof(merge)); } if (searchCondition == null) { throw new ArgumentNullException(nameof(searchCondition)); } if (setter == null) { throw new ArgumentNullException(nameof(setter)); } if (deleteCondition == null) { throw new ArgumentNullException(nameof(deleteCondition)); } return(((MergeDefinition <TTarget, TSource>)merge).AddOperation( MergeDefinition <TTarget, TSource> .Operation.UpdateWithDelete(searchCondition, setter, deleteCondition))); }
/// <summary> /// Adds new update operation to merge and returns new merge command with added operation. /// This operation updates record in target table using data from the same fields of source record /// for each record that was matched in source and target, if it wasn't processed by previous operations. /// </summary> /// <typeparam name="TTarget">Target and source records type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TTarget> UpdateWhenMatched <TTarget>(this IMergeableSource <TTarget, TTarget> merge) where TTarget : class { if (merge == null) { throw new ArgumentNullException(nameof(merge)); } return(((MergeDefinition <TTarget, TTarget>)merge).AddOperation( MergeDefinition <TTarget, TTarget> .Operation.Update(null, null))); }
/// <summary> /// Adds new insert operation to merge and returns new merge command with added operation. /// This operation inserts new record to target table using data from the same fields of source record /// for each new record from source, not processed by previous operations. /// </summary> /// <typeparam name="TTarget">Target and source records type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TTarget> InsertWhenNotMatched <TTarget>(this IMergeableSource <TTarget, TTarget> merge) where TTarget : class { if (merge == null) { throw new ArgumentNullException("merge"); } return(((MergeDefinition <TTarget, TTarget>)merge).AddOperation( MergeDefinition <TTarget, TTarget> .Operation.Insert(null, null))); }
/// <summary> /// IMPORTANT: This operation supported only by Microsoft SQL Server. /// Adds new delete by source operation to merge and returns new merge command with added operation. /// This operation removes record in target table for each record that was matched only in target /// and wasn't processed by previous operations. /// </summary> /// <typeparam name="TTarget">Target record type.</typeparam> /// <typeparam name="TSource">Source record type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TSource> DeleteWhenNotMatchedBySource <TTarget, TSource>( this IMergeableSource <TTarget, TSource> merge) where TTarget : class where TSource : class { if (merge == null) { throw new ArgumentNullException(nameof(merge)); } return(((MergeDefinition <TTarget, TSource>)merge).AddOperation( MergeDefinition <TTarget, TSource> .Operation.DeleteBySource(null))); }
/// <summary> /// IMPORTANT: This operation supported only by Oracle Database. /// Adds new update with delete operation to merge and returns new merge command with added operation. /// This operation updates record in target table using data from the same fields of source record /// for each record that was matched in source and target, if it wasn't processed by previous operations. /// After that it removes updated records if they are matched by delete predicate. /// </summary> /// <typeparam name="TTarget">Target and source records type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <param name="deleteCondition">Delete execution condition over updated target and source records.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TTarget> UpdateWhenMatchedThenDelete <TTarget>( this IMergeableSource <TTarget, TTarget> merge, Expression <Func <TTarget, TTarget, bool> > deleteCondition) where TTarget : class { if (merge == null) { throw new ArgumentNullException(nameof(merge)); } if (deleteCondition == null) { throw new ArgumentNullException(nameof(deleteCondition)); } return(((MergeDefinition <TTarget, TTarget>)merge).AddOperation( MergeDefinition <TTarget, TTarget> .Operation.UpdateWithDelete(null, null, deleteCondition))); }
/// <summary> /// Adds new insert operation to merge and returns new merge command with added operation. /// This operation inserts new record to target table using data from the same fields of source record /// for each new record from source that passes filtering with specified predicate, if it wasn't /// processed by previous operations. /// </summary> /// <typeparam name="TTarget">Target and source records type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <param name="searchCondition">Operation execution condition over source record.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TTarget> InsertWhenNotMatchedAnd <TTarget>( this IMergeableSource <TTarget, TTarget> merge, Expression <Func <TTarget, bool> > searchCondition) where TTarget : class { if (merge == null) { throw new ArgumentNullException(nameof(merge)); } if (searchCondition == null) { throw new ArgumentNullException(nameof(searchCondition)); } return(((MergeDefinition <TTarget, TTarget>)merge).AddOperation( MergeDefinition <TTarget, TTarget> .Operation.Insert(searchCondition, null))); }
/// <summary> /// IMPORTANT: This operation supported only by Microsoft SQL Server. /// Adds new delete by source operation to merge and returns new merge command with added operation. /// This operation removes record in target table for each record that was matched only in target /// and passed filtering with operation predicate, if it wasn't processed by previous operations. /// </summary> /// <typeparam name="TTarget">Target record type.</typeparam> /// <typeparam name="TSource">Source record type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <param name="searchCondition">Operation execution condition over target record.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TSource> DeleteWhenNotMatchedBySourceAnd <TTarget, TSource>( this IMergeableSource <TTarget, TSource> merge, Expression <Func <TTarget, bool> > searchCondition) where TTarget : class where TSource : class { if (merge == null) { throw new ArgumentNullException(nameof(merge)); } if (searchCondition == null) { throw new ArgumentNullException(nameof(searchCondition)); } return(((MergeDefinition <TTarget, TSource>)merge).AddOperation( MergeDefinition <TTarget, TSource> .Operation.DeleteBySource(searchCondition))); }
/// <summary> /// Adds new update operation to merge and returns new merge command with added operation. /// This operation updates record in target table using user-defined values for target columns /// for each record that was matched in source and target, if it wasn't processed by previous operations. /// </summary> /// <typeparam name="TTarget">Target record type.</typeparam> /// <typeparam name="TSource">Source record type.</typeparam> /// <param name="merge">Merge command builder interface.</param> /// <param name="setter">Update record expression using target and source records. /// Expression should be a call to target record constructor with field/properties initializers to be recognized by API.</param> /// <returns>Returns new merge command builder with new operation.</returns> public static IMergeable <TTarget, TSource> UpdateWhenMatched <TTarget, TSource>( this IMergeableSource <TTarget, TSource> merge, Expression <Func <TTarget, TSource, TTarget> > setter) where TTarget : class where TSource : class { if (merge == null) { throw new ArgumentNullException(nameof(merge)); } if (setter == null) { throw new ArgumentNullException(nameof(setter)); } return(((MergeDefinition <TTarget, TSource>)merge).AddOperation( MergeDefinition <TTarget, TSource> .Operation.Update(null, setter))); }